views:

32

answers:

1

Hi,

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 better solution to the HTML code, then please suggest.

+2  A: 

Yes, append works nice:

$('#t1').append('<div id="block1"><span>bla bla bla</span></div>');
Darin Dimitrov
However this will not support the exactly what the OP wants. Just make the id `block` generic with a counter and it should be fine
Shervin
Are you sure append will work? Won't it just add onto the end of #t1? I want it to appear inside #t1 before the closing div. Plus any further additions to be sequential after that.
Haven't you looked at the link? Analyzing it with FireBug it does exactly what you expect.
Darin Dimitrov
Yes sorry I didn't see the link, that appears to work perfectly. Thank you.