admin管理员组

文章数量:1434966

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/

本文标签: javascriptHow to append ampnbsp inside the last ltpgt tag with jqueryStack Overflow