3

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.

1 Answer 1

1

Yes, append works nice:

$('#t1').append('<div id="block1"><span>bla bla bla</span></div>');
Sign up to request clarification or add additional context in comments.

4 Comments

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
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.
Yes sorry I didn't see the link, that appears to work perfectly. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.