Embed HTML in jQuery

If I have an HTML block, for example: -

<div id="t1">
    <div>
        <input type="text" value="Bla"/>
    </div>
    <!--INSERT JQUERY HTML HERE--> </div>

How do I put the inserted HTML generated by the user, click where is my comment? With each user action, I will need to insert a block of code that will look like this:

<div id="block1"><span>bla bla bla</span></div>

so in theory, after a few clicks, we could get 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 know about the function append(), but I'm not sure if this will work here.

If anyone has a better solution for HTML code, please suggest.

+3
source share
1 answer

Yes, append works nice :

$('#t1').append('<div id="block1"><span>bla bla bla</span></div>');
+1
source

Source: https://habr.com/ru/post/1763498/


All Articles