Home > Software engineering >  How to append HTML content with CSS, JS in current webpage using pure javascript?
How to append HTML content with CSS, JS in current webpage using pure javascript?

Time:04-12

For example,

var newElement = document.createElement('div');
newElement.innerHTML = "<p>new content</p><script>alert('Hello World!')</script>";
element.appendChild(newElement);​​​​​​​​​​​​​​​​

Result: "new content" is appended in page but there will be no alert saying Hello World!

I have tried innerHTML, insertAdjacentHTML, append, appendChild methods. But the problem is JS and CSS not loading dynamically.

In jQuery, after() works

  • Related