In most cases, this is just the content you want to replace, not the element itself. If you really replace the element, you will find that the event handlers associated with it are no longer bound (because they were attached to the old one).
Content Replacement
Replacing the contents of an element is simple:
var element;
element = document.getElementById("logo");
if (element) {
element.innerHTML = "-new content-";
}
innerHTML , (, ). (. innerHTML .)
iself
, :
var element, newElement, parent;
element = document.getElementById("logo");
if (element) {
parent = element.parentNode;
newElement = document.createElement('div');
newElement.id = "logo";
newElement.innerHTML = "-new content here-";
parent.insertBefore(newElement, element);
parent.removeChild(element);
}
innerHTML DOM
, innerHTML, . , jQuery, Prototype .., , .
DOM, innerHTML ( , div /, ). , , , createElement, appendChild .., , innerHTML . HTML - , , . DOM, , . , , innerHTML - .