How to write html code dynamically using JavaScript?

How to write html code dynamically using JavaScript?

The innerHTML property can be used to write html code dynamically using JavaScript. By using innerHTML, there is no need to refresh the page to change the page's content. This makes the website feel quicker to the user.

document.getElementById('ID of element').innerHTML = 'content';

By using getElementById, we get the id of the element whose content is to be changed, and replace it with 'content'.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.