最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin5PV0评论

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/

Post a comment

comment list (0)

  1. No comments so far