最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to append &nbsp inside the last <p> tag with jquery? - Stack Overflow

programmeradmin2浏览0评论

How to append   to the end of the last tag with jQuery? For example, my html would be something like this:

<div>
    <p>line1</p>
    <p>line2</p>  
</div>  

I want the end result to be:

<div>
    <p>line1</p>
    <p>line2 &nbsp;</p>  
</div>  

How to append &nbsp; to the end of the last tag with jQuery? For example, my html would be something like this:

<div>
    <p>line1</p>
    <p>line2</p>  
</div>  

I want the end result to be:

<div>
    <p>line1</p>
    <p>line2 &nbsp;</p>  
</div>  
Share Improve this question edited Jul 30, 2013 at 18:32 Joe 15.6k8 gold badges51 silver badges57 bronze badges asked Jul 30, 2013 at 18:28 hardy1337hardy1337 231 silver badge5 bronze badges 1
  • You might want to consider just using the :last-child class (not available in ie6, ie7, ie8, available in ie9 and good browsers) and just adding some slight right-margin instead of adding content. – Kzqai Commented Jul 30, 2013 at 18:59
Add a ment  | 

1 Answer 1

Reset to default 7

Like this:

$("div p:last").append("&nbsp;");

See here:

http://jsfiddle/d8AGr/

发布评论

评论列表(0)

  1. 暂无评论