javascript - Append the div content jquery - Stack Overflow

Hi I have a div with content like this <div><strong>some content....<strong><div

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 badges
Add a ment  | 

3 Answers 3

Reset to default 6

Just 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745316692a4622252.html

相关推荐

  • javascript - Append the div content jquery - Stack Overflow

    Hi I have a div with content like this <div><strong>some content....<strong><div

    3小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信