addEventListener gone after appending innerHTML

Any time you set the innerHTML property you are overwriting any previous HTML that was set there. This includes concatenation assignment, because element.innerHTML += ‘<b>Hello</b>’; is the same as writing element.innerHTML = element.innerHTML + ‘<b>Hello</b>’; This means all handlers not attached via HTML attributes will be “detached”, since the elements they were attached to no … Read more

innerHTML removes attribute quotes in Internet Explorer

IE innerHTML is very annoying indeed. I wrote this function for it, which may be helpfull? It quotes attributes and sets tagnames to lowercase. By the way, to make it even more annoying, IE’s innerHTML doesn’t remove quotes from non standard attributes. Edit based on comments The function now processes more characters in attribute values … Read more

Uncaught Typeerror: cannot read property ‘innerHTML’ of null

var idPost=document.getElementById(“status”).innerHTML; The ‘status’ element does not exist in your webpage. So document.getElementById(“status”) return null. While you can not use innerHTML property of NULL. You should add a condition like this: if(document.getElementById(“status”) != null){ var idPost=document.getElementById(“status”).innerHTML; }

Remove all content using pure JS

I think a browser rightfully assumes a page with content-type text/html will always be a web page – so whilst you may do something like… document.body.innerHTML = ”; It will still have some HTML hanging around. You could try… document.documentElement.innerHTML = ”; …which left me with <html></html>. Yi Jiang did suggest something clever. window.location = … Read more

reading innerHTML of HTML form with VALUE attribute (& its value) of INPUT tags

That’s because value is a property when the textbox is filled in, not an attribute. This means that .value works fine, but it’s not part of the actual DOM as an attribute (like <input value=”…”>). You’d need to set it explicitly: document.getElementById(“html”).onclick = function() { var elems = document.getElementsByName(“ipForm”)[0] .getElementsByTagName(“input”); for (var i = 0; … Read more

Alternative for innerHTML?

The recommended way is through DOM manipulation, but it can be quite verbose. For example: // <p>Hello, <b>World</b>!</p> var para = document.createElement(‘p’); para.appendChild(document.createTextNode(‘Hello, ‘)); // <b> var b = document.createElement(‘b’); b.appendChild(document.createTextNode(‘World’); para.appendChild(b); para.appendChild(document.createTextNode(‘!’)); // Do something with the para element, add it to the document, etc. EDIT In response to your edit, in order to … Read more