Javascript set text of div
you can use following helper function: Show
Where Here is working example. Additionaly - today (2018.07.01) I made speed comparison for jquery and pure js solutions ( MacOs High Sierra 10.13.3 on Chrome 67.0.3396.99 (64-bit), Safari 11.0.3 (13604.5.6), Firefox 59.0.2 (64-bit) ):
The jquery solution was slower than pure js solution: 69% on firefox, 61% on safari, 56% on chrome. The fastest browser for pure js was firefox with 560M operations per second, the second was safari 426M, and slowest was chrome 122M. So the winners are pure js and firefox (3x faster than chrome!) You can test it in your machine: https://jsperf.com/js-jquery-html-content-change The HTML DOM allows JavaScript to change the content of HTML elements. Changing HTML ContentThe easiest way to modify the content of an HTML element is by using the To change the content of an HTML element, use this syntax: document.getElementById(id).innerHTML = new HTML This example changes the content of a Example
Hello World!
Try it Yourself » Example explained:
This example changes the content of an Example
Old Heading
Try it Yourself » Example explained:
Changing the Value of an AttributeTo change the value of an HTML attribute, use this syntax:
document.getElementById(id).attribute = new value This example changes the value of the src attribute of an
|