Skip to content Skip to sidebar Skip to footer

How To Add Div Tag In-between Two Paragraphs When Wrapped Inside Main Div Using Jquery

I have to show a banner ad for each article somewhere in between the article text, let us say after 2nd or 3rd paragraph. sample example of article on jsFiddle if you have checked

Solution 1:

With jQuery you can use below code:

$('<div class="ContentBanner"> BANNER WILL SHOW UP HERE</div>').insertAfter('.ArticleContent p:nth-child(3) ');

This should work!!!!

http://jsfiddle.net/eehtK/

Solution 2:

$(".ContentBanner").insertAfter(".ArticleContent p:eq(1)")

DEMO

Solution 3:

$("div.ArticleContent p").each(function(index,item)
    {
        if(index==1 || index==2)
        {
            var divBanner='<div class="ContentBanner"> BANNER WILL SHOW UP HERE</div>';

            $(this).append(divBanner);
       }        
  });

Post a Comment for "How To Add Div Tag In-between Two Paragraphs When Wrapped Inside Main Div Using Jquery"