Irene T.
Irene T.

Reputation: 1393

Inserting a div after the second image jquery

i am using the code bellow to insert a div after the first image and it works great.. Is it possible to insert it after the second image?

my code is:

$(document).ready(function () {
    $(".gdl-blog-full").find("img:first").after("<div id='1' style='width:800px; height:90px; float: left; margin-top:10px; margin-bottom:15px;'><div class='gad' style='width: 728px; height:90px; float: left; margin-left: 36px;'></div></div>");
});

Upvotes: 0

Views: 69

Answers (2)

Try :eq is same as :nth()

$(".gdl-blog-full").find("img:nth(1)")

:nth(),:eq() index starts from 0

or :nth-child()

$(".gdl-blog-full").find("img:nth-child(2)")

:nth-child() index starts from 1

or .eq()

$(".gdl-blog-full").find("img").eq(1)

Upvotes: 2

Ankit Tyagi
Ankit Tyagi

Reputation: 2375

Use eq : further reading :eq

$( document ).ready(function() {                     
    $(".gdl-blog-full").find("img:eq(1)").after("<div id='1' style='width:800px; height:90px; float: left; margin-top:10px; margin-bottom:15px;'><div class='gad' style='width: 728px; height:90px; float: left; margin-left: 36px;'></div></div>");
});

Upvotes: 1

Related Questions