What is innerHTML on input elements?

Setting the value is normally used for input/form elements. innerHTML is normally used for div, span, td and similar elements. value applies only to objects that have the value attribute (normally, form controls). innerHtml applies to every object that can contain HTML (divs, spans, but many other and also form controls). They are not equivalent … Read more

How to unit test DOM manipulation (with jasmine)

I’ve been using a helpful addition to jasmine called jasmine-jquery available on github. It gives you access to a number of useful extra matcher functions, to assert jquery objects and their properties. In particular the features I have found useful so far are asserting on attributes of dom elements, and spying on events such as … Read more

using document.createDocumentFragment() and innerHTML to manipulate a DOM

While DocumentFragment does not support innerHTML, <template> does. The content property of a <template> element is a DocumentFragment so it behaves the same way. For example, you can do: var tpl = document.createElement(‘template’); tpl.innerHTML = ‘<tr><td>Hello</td><td>world</td></tr>’; document.querySelector(‘table’).appendChild(tpl.content); The above example is important because you could not do this with innerHTML and e.g. a <div>, because … Read more

jQuery empty() vs remove()

empty() will empty the selection of its contents, but preserve the selection itself. remove() will empty the selection of its contents and remove the selection itself. Consider: <div> <p><strong>foo</strong></p> </div> $(‘p’).empty(); // –> “<div><p></p></div>” // whereas, $(‘p’).remove(); // –> “<div></div>” Both of them remove the DOM objects and should release the memory they take up, … Read more

How to move all HTML element children to another parent using JavaScript?

Basically, you want to loop through each direct descendent of the old-parent node, and move it to the new parent. Any children of a direct descendent will get moved with it. var newParent = document.getElementById(‘new-parent’); var oldParent = document.getElementById(‘old-parent’); function move() { while (oldParent.childNodes.length > 0) { newParent.appendChild(oldParent.childNodes[0]); } } #old-parent { background-color: red; } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)