Insert HTML with jQuery

怎甘沉沦 提交于 2019-12-10 10:23:19

问题


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:


Yes, append works nice:

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


来源:https://stackoverflow.com/questions/3653301/insert-html-with-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!