0 votes
1 view
in Web Technology by (6.8k points)

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

1 Answer

0 votes
by (13k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...