Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a simple JavaScript example that updates DOM

Tags:

javascript

dom

I am looking for a simple JavaScript example that updates DOM.
Any suggestions?

like image 903
Ravi Chhabra Avatar asked Sep 04 '08 17:09

Ravi Chhabra


1 Answers

Here is a short pure-javascript example. Assume you have a div with the id "maincontent".

var newnode = document.createTextNode('Here is some text.');
document.getElementById('maincontent').appendChild(newnode);

Of course, things are a lot easier (especially when you want to do more complicated things) with jQuery.

like image 187
Neall Avatar answered Nov 03 '22 01:11

Neall