jQuery DOM element creation vs innerHTML

Posted by Mohammad on Stack Overflow See other posts from Stack Overflow or by Mohammad
Published on 2010-06-12T07:46:31Z Indexed on 2010/06/12 7:52 UTC
Read the original article Hit count: 354

Filed under:
|
|
|

While having one of my questions answered, cletus mentioned that when creating elements in jQuery it's better to use direct DOM element creation, instead of innerHTML. I tried googling it but I wasn't able to find a good article with comparisons.

I've provided this code bellow as an example and I was wondering if someone could help me rewrite it in direct DOM element creation form in hope that i would also learn the difference afterwards.

var img = $(this);
img.append('<p class="cap"><a href="'+img.parent().attr('href')+'">'+
img.attr('title')+'</p></a>');

Thanks so much.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about dom