Thursday, 23 February 2012

jQuery Tip: How to properly append content to the DOM

Doing like this is sloppy and bad:
$('<p>Add to the Dom</p>').appendTo('body');
It can get extremely complicated sometimes. Imagine if you want to add a class or add some styling to it. So instead, use this format.

$('<p></p>',{
    text: "Add to the Dom",
   class: "ClassName"
}).insertAfter('h1');

No comments:

Post a Comment