Anirudha Gupta
Anirudha Gupta

Reputation: 9289

how to append on sibling in jQuery?

I have this code

<div class="data">
    
    <div class="another"></div>
    <!-- need to add element here -->
    
</div>

I want to add the element where I put comment using jQuery how I can append sibling of another using jQuery

Upvotes: 57

Views: 51477

Answers (3)

Richard Dalton
Richard Dalton

Reputation: 35793

I think you want to use the .after() function:

$('div.another').after('<div>');

Upvotes: 51

Alex R.
Alex R.

Reputation: 4754

If you specifically want to insert after the another div element, try insertAfter:

$('<div>Another 2</div>').insertAfter($('.another'));

In the $('.another') part, you can otherwise specify the target more precisely.

Upvotes: 82

metaforce
metaforce

Reputation: 1377

try:

$('div#data').append('your HTML');

Upvotes: 7

Related Questions