admin管理员组文章数量:1419624
Hi I have a div with content like this
<div><strong>some content
....</strong></div>
How can I add another element to the div after <strong>
, how to add <span>
element after <strong>
?
Thank you
Hi I have a div with content like this
<div><strong>some content
....</strong></div>
How can I add another element to the div after <strong>
, how to add <span>
element after <strong>
?
Thank you
Share Improve this question asked Dec 25, 2009 at 20:43 Gandalf StormCrowGandalf StormCrow 26.2k71 gold badges179 silver badges268 bronze badges3 Answers
Reset to default 6Just use append
on your div
element:
$('#divId').append('<span>Hi</span>');
It will insert the span
element inside the div
, at the end of the child node list.
Edit: In response to your ment, to remove it, since you added the element with append
, you can get it selecting the last-child:
$("#divId span:last-child").remove();
Or you could remove all the span
elements within the div
:
$("#divId span").remove();
If the <div>
is the only one on the HTML page in question:
$('div strong').after('<span>Span element</span>')
See http://docs.jquery./Manipulation/after#content
append and after are easily found in the documentation
本文标签: javascriptAppend the div content jqueryStack Overflow
版权声明:本文标题:javascript - Append the div content jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745316692a2653187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论