jQuery html() in Firefox (uses .innerHTML) ignores DOM changes

Firefox doesn’t update the value attribute of a DOM object based on user input, just its value property – pretty quick work around exists. DOM: function DisplayTextBoxValue(){ var element = document.getElementById(‘textbox’); // set the attribute on the DOM Element by hand – will update the innerHTML element.setAttribute(‘value’, element.value); alert(document.getElementById(“container”).innerHTML); return false; } jQuery plugin that … Read more

Javascript – Append HTML to container element without innerHTML

I am surprised that none of the answers mentioned the insertAdjacentHTML() method. Check it out here. The first parameter is where you want the string appended and takes (“beforebegin”, “afterbegin”, “beforeend”, “afterend”). In the OP’s situation you would use “beforeend”. The second parameter is just the html string. Basic usage: var d1 = document.getElementById(‘one’); d1.insertAdjacentHTML(‘beforeend’, … Read more

nodeValue vs innerHTML and textContent. How to choose? [duplicate]

Differences between textContent/innerText/innerHTML on MDN. And a Stackoverflow answer about innerText/nodeValue. Summary innerHTML parses content as HTML, so it takes longer. nodeValue uses straight text, does not parse HTML, and is faster. textContent uses straight text, does not parse HTML, and is faster. innerText Takes styles into consideration. It won’t get hidden text for instance. … Read more

Angular 2 – innerHTML styling

update 2 ::slotted ::slotted is now supported by all new browsers and can be used with ViewEncapsulation.ShadowDom https://developer.mozilla.org/en-US/docs/Web/CSS/::slotted update 1 ::ng-deep /deep/ was deprecated and replaced by ::ng-deep. ::ng-deep is also already marked deprecated, but there is no replacement available yet. When ViewEncapsulation.Native is properly supported by all browsers and supports styling accross shadow DOM … Read more

Can scripts be inserted with innerHTML?

Here is a method that recursively replaces all scripts with executable ones: function nodeScriptReplace(node) { if ( nodeScriptIs(node) === true ) { node.parentNode.replaceChild( nodeScriptClone(node) , node ); } else { var i = -1, children = node.childNodes; while ( ++i < children.length ) { nodeScriptReplace( children[i] ); } } return node; } function nodeScriptClone(node){ var … Read more

Advantages of createElement over innerHTML?

There are several advantages to using createElement instead of modifying innerHTML (as opposed to just throwing away what’s already there and replacing it) besides safety, like Pekka already mentioned: Preserves existing references to DOM elements when appending elements When you append to (or otherwise modify) innerHTML, all the DOM nodes inside that element have to … Read more