Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

What is the correct way to write dynamic HTML in JavaScript?

1 Answer

0 votes
by (13.1k points)
  1.  Using innerHTML on a node:
    var node=document.getElementById(‘node-id’);

 node.innerHTML(‘<p> some dynamic html</p>’);

  1. Using DOM methods:

var node=document.getElementById(‘node-id’);

var newNode=document.createElement(‘p’);

newNode.appendChild(document.createTextNode(‘Your dynamic html’));

node.appendChild(newNode);

Utilizing the DOM API strategies may be the perfectionist approach to do stuff, yet innerHTML has been demonstrated to be a lot quicker and is utilized in the engine in JavaScript libraries like jQuery.

Want to full stack development? Check out the full stack developer course from Intellipaat.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...