jquery - Inserting a newly created div into the DOM -
jquery - Inserting a newly created div into the DOM -
i want append div below, has 2 children, #galleryheader div in dom.
<div class=open_folder_icon> <img class="folder_icon" src="images/folder_open.png" alt="open folder" /> <div class="folder_name" >root</div> </div>
i want
$('<div>').appendto(#galleryheader);
but replace simple 'div' here more complicated div. there clean way that?
thanks
not sure question is, if append:
it should go other direction using append
:
$('#galleryheader').append('<div>');
where <div>
more complicated div string.
see documentation here.
alternately, should able do:
$('<div>').appendto('#galleryheader');
in either case, need create sure #galleryheader
in quotation marks since acting selector.
if question creating complicated div:
jquery lets create element string quite easily. build element in string like:
var mydiv = '<div class=open_folder_icon>' + '<img class="folder_icon" src="images/folder_open.png" alt="open folder" />' + '<div class="folder_name" >root</div>' + '</div>';
and utilize in jquery statement:
$(mydiv).appendto('#galleryheader')
you can straight place div string $()
expression, think placing in own variable , constructing line line easier read huge one-liner of html.
another alternative utilize templating engine such underscore or handlebars generate string feed jquery.
under hood, jquery calling appropriate dom functions create html dom element objects string pass it.
jquery
Comments
Post a Comment