Insert HTML with jQuery
If I have a block of HTML like:-
<div id="t1">
<div>
<input type="text" value="Bla"/>
</div>
<!--INSERT JQUERY HTML HERE--> </div>
How would I go about inserted HTML generated by a user click where my comment is? On each user action, I'd need to insert a block of code which will follow something like:
<div id="block1"><span>bla bla bla</span></div>
so in theory after several clicks we could end up with something like:
<div id="t1">
<div>
<input type="text" value="Bla"/>
</div>
<div id="block1"><span>bla bla bla</span></div>.
<div id="block2"><span>bla bla bla</span></div>.
<div id="block3"><span>bla bla bla</span></div>.
</div>
I'm aware of the append()
function but I'm unsure as to if this will work here.
If anyone has any be开发者_JS百科tter solution to the HTML code, then please suggest.
Yes, append works nice:
$('#t1').append('<div id="block1"><span>bla bla bla</span></div>');
精彩评论