user2487967
user2487967

Reputation: 83

Append a span to a specific span on page

Code as it appears now:

<p class="intro" id="186949"><span class="namepart"><span class="name">john cena</span></span>

Code as I want it to appear:

<p class="intro" id="186949"><span class="namepart"><span class="name">john cena</span><span class="special">name2</span></span>

I'd like to append another span to the end of "john cena" Using Jquery, but only to that specific post, with the ID "186949"

I know I have to use append, but I don't know how to ensure that the span goes only in that post, and after the name span.

Upvotes: 0

Views: 40

Answers (2)

Sergio
Sergio

Reputation: 28837

Check here Fiddle

var content = '<span class="special">name2</span>';
$(content).insertAfter('#186949 .name');

Upvotes: 1

Karl-Andr&#233; Gagnon
Karl-Andr&#233; Gagnon

Reputation: 33870

Try this :

$('#186949 .namepart .name').after($('<span/>', {class : 'special', text : 'name2'}))

Upvotes: 5

Related Questions