Question

In order to preserve my event handlers i know that i need to preserve the elements node.

the goal is to add the html to the page without rewriting the html on the page.

I really have no idea what to do here, i have never needed to do this before.

Here is what i am trying to add to the page without losing the handlers of my current elements.

var tagged_element_ = document.createElement(tag);
tagged_element_.innerHTML = "<" + tagged_element_.tagName + " id='" + id + "'></" + tagged_element_.tagName + ">";

Normally i would just do element.innerHTML += tagged_element_.innerHTML; but that's not working.

This is a javascript question, do not mention or supply any forms of JQuery.

Was it helpful?

Solution

Use Node.appendChild.

// Create a new paragraph element, and append it to the end of the document body
var p = document.createElement("p");
document.body.appendChild(p);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top