jQuery:将内容添加到div的末尾 [英] jQuery: add content to end of div

查看:1041
本文介绍了jQuery:将内容添加到div的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个HTML:

<div class="region-list" id="region_North_America">
    <strong>North America</strong>
</div>

,要在结果强壮的元素之后添加更多div:

and want to add more divs after the strong element to result:

<div class="region-list" id="region_North_America">
    <strong>North America</strong>
    <div> ... </div>
    <div> ... </div>
    <div> ... </div>
</div>

我正在尝试:

var row_str = '<div>content here</div>';
$('#region_North_America div:last').html(row_str);

但是,html没有变化.之所以如此,是因为所选元素中没有div.

However, there is no change to the html. This is probably so since there is no div within the element selected.

我知道js正在使之成为此代码,因为我可以将row_str的内容打印到控制台.

I know that the js is making it to this code because I can print the content of row_str to the console.

那么,我如何到达该容器元素的末尾以添加新项目?

So, how can I get to the end of that container element to add the new items?

谢谢.

推荐答案

尝试:

$("#region_North_America").append(row_str);

使用 append() .

这篇关于jQuery:将内容添加到div的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆