Javascript Tutorial | Create & Append DOM Element's




In this lecture I’ll be making a virtual DOM object within Javascript. Then I’ll tell the DOM to add the relevant element using the information from our virtual DOM object. This will allow me to produce an element from Javascript.

This tutorial is brought to you by http://www.avelx.co.uk/ – Coding tutorials to help you grow.

Original source


10 responses to “Javascript Tutorial | Create & Append DOM Element's”

  1. var d = {};
    d.make = document.createElement;
    d.nest = function(parent, child) { return parent.appendChild(child); };

    var divL1= d.make('div'); divL1.id='divL1'; d.nest(document.body, divL1);
    var divL2 = d.make('div'); divL2 .id='divL2 '; d.nest(divL1, divL2 );
    var divL3 = d.make('div'); divL3.id='divL3'; d.nest(divL2, divL3);
    .
    .
    .
    We don't need to write html – beyond the basic, empty html skeleton. We can actually write our application in javascript in a nested, outline format that somewhat mimics an html outline, for easier readability.

Leave a Reply