user2990084
user2990084

Reputation: 2840

Insert list elements with jquery after img

I have this html structure:

<ul id="comments_notifications_list" class="dropdown-menu">
    <li><img src="loader.png" class="noty" style="display: none;"><li>
</ul>

Now i am trying to add add some content after the loader. The code should be always updated, so after() will not work because the <li> will be incremented.

$('.noty').after('<li> Name: ' + jd.name + '</li>');

How can i do that? basically the <li> elements should be dynamic inserted and the img always preserved.

Upvotes: 0

Views: 56

Answers (1)

kneeki
kneeki

Reputation: 2692

I was confused reading your post originally...

// Create a new <li /> after the <li> containing .noty
$('.noty').parent().after("<li>blah</li>");

// Insert new content after .noty
$('.noty').after("<li>blah</li>");

// Insert new content after the UL containing .noty
$('.noty').closest("ul").after("<p>Foo</p>");

Upvotes: 1

Related Questions