innerhtml

jQuery DOM element creation vs innerHTML

ⅰ亾dé卋堺 提交于 2020-01-05 03:17:00
问题 While having one of my questions answered, cletus mentioned that when creating elements in jQuery it's better to use direct DOM element creation , instead of innerHTML . I tried googling it but I wasn't able to find a good article with comparisons. I've provided this code bellow as an example and I was wondering if someone could help me rewrite it in direct DOM element creation form in hope that i would also learn the difference afterwards. var img = $(this); img.append('<p class="cap"><a

what to use instead of document.write or InnerHTML?

我只是一个虾纸丫 提交于 2020-01-04 18:14:06
问题 Say I have an html code like this: <script> // just an example function to get data from input function getNumber(form) { var userInput = new Number; // convert form values into numbers userInput = Number(form.enteredNumber.value); return userInput; } function countNumbers(form) { var lastNumber = getNumber(form); // the last number to be counted for (i = 1; i <= lastNumber; i++) { //count the numbers document.write(" "+i); // put the numbers on the page if((i % 10) == 0) { document.write("

How to get innerHTML from a div?

萝らか妹 提交于 2020-01-03 20:03:34
问题 I need to save the innerHTML of a div and store it in a cookie. Here is my basic code. //The div-saving function function addStatus(sName){ getElement("bottomDiv").innerHTML += sName + "<br>"; document.cookie="status=" + sName + "<br>"; } //The button clicking function function clk(){ num++; document.cookie = "num=" + num; switch(num){ case 25: addStatus("25: Alright! Let the games begin!"); break; case 50: addStatus("50: Woah! Getting into the high numbers!"); break; } } What ends up

How to get innerHTML from a div?

时光总嘲笑我的痴心妄想 提交于 2020-01-03 20:03:11
问题 I need to save the innerHTML of a div and store it in a cookie. Here is my basic code. //The div-saving function function addStatus(sName){ getElement("bottomDiv").innerHTML += sName + "<br>"; document.cookie="status=" + sName + "<br>"; } //The button clicking function function clk(){ num++; document.cookie = "num=" + num; switch(num){ case 25: addStatus("25: Alright! Let the games begin!"); break; case 50: addStatus("50: Woah! Getting into the high numbers!"); break; } } What ends up

How to update Select menu with AJAX w/out <div> inside form

筅森魡賤 提交于 2020-01-03 17:27:15
问题 I am using an ajax call to update a select menu. The ajax call puts the list into my select menu by running from a different .php file. Here is the JS insertion snippet: if (req.status == 200) { document.getElementById('countydiv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } And here is the HTML: <label for="county">County:</label> <div id="countydiv"> <select name="county"> <option>Select State First</option> </select> </div>

In JavaScript, how can serializer part of the DOM to XHTML?

亡梦爱人 提交于 2020-01-03 13:58:17
问题 I would like to serialize part of the DOM to XHTML (valid XML). Let's assume I have just one element inside <body> , and that this is the element I want to serialize: <div> <hr> <img src="/foo.png"> </div> With this, document.innerHTML gives me almost what I want, except it returns HTML, not XHTML (i.e. the <hr> and <img> won't be properly closed). Since innerHTML doesn't do the trick, how can I serialize part of the DOM to XHTML? 回答1: I am not sure if using another language (on top of the

In JavaScript, how can serializer part of the DOM to XHTML?

送分小仙女□ 提交于 2020-01-03 13:58:03
问题 I would like to serialize part of the DOM to XHTML (valid XML). Let's assume I have just one element inside <body> , and that this is the element I want to serialize: <div> <hr> <img src="/foo.png"> </div> With this, document.innerHTML gives me almost what I want, except it returns HTML, not XHTML (i.e. the <hr> and <img> won't be properly closed). Since innerHTML doesn't do the trick, how can I serialize part of the DOM to XHTML? 回答1: I am not sure if using another language (on top of the

Run function once per event burst with jQuery

≡放荡痞女 提交于 2020-01-01 07:21:41
问题 I'm using jQuery to listen to DOMSubtreeModified event, and then execute a function. What I need is a way to only run a function once per event burst. So in this case, the event will only run after 1 second, and again after 3 seconds. What is the best way to do this? jQuery $(function(){ setTimeout(function(){ $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML

Run function once per event burst with jQuery

你离开我真会死。 提交于 2020-01-01 07:21:12
问题 I'm using jQuery to listen to DOMSubtreeModified event, and then execute a function. What I need is a way to only run a function once per event burst. So in this case, the event will only run after 1 second, and again after 3 seconds. What is the best way to do this? jQuery $(function(){ setTimeout(function(){ $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML

Modifying the innerHTML of a <style> element in IE8

断了今生、忘了曾经 提交于 2020-01-01 04:12:05
问题 I am creating a style element and I need to put some CSS into it. The below code works in Chrome, Safari and FF, but fails in IE8: var styleElement = document.createElement("style"); styleElement.type = "text/css"; styleElement.innerHTML = "body{background:red}"; document.head.appendChild(styleElement); In IE8, the code fails when it comes to the innerHTML part. I've tried doing: var inner = document.createTextNode("body{background:red}"); styleElement.appendChild(inner); But this also fails