Hi everyone,
I'm trying to create a new HTML in JavaScript using createElement function and I want to add content within that element. The easiest way to do this, is using
For example, would this be considered 'safe'?
I'm trying to create a new HTML in JavaScript using createElement function and I want to add content within that element. The easiest way to do this, is using
createdElement.innerHTML = "content";. However, I've been seeing a couple resources where using innerHTMl is a potential security risk. What I don't know is in what context is it a security risk. Is it just a security risk in general or is it security risk when it is used in particular way?For example, would this be considered 'safe'?
JavaScript:
var result = document.getElementById("result");
var createPTag = document.createElement("p");
createPTag.innerHTML = "Testing";
result.appendChild(createPTag);