1

I am trying to add content (div) after an image using append(). All the list items are dynamically generated, I can only add class to the 'ul'.

Here's the fiddle: http://jsfiddle.net/krish7878/ggyDf/3/

<ul class="footer-8-flickr">
  <li> <a href="#"> <img src="#"></a></li>
  <li> <a href="#"> <img src="#"></a></li>
  <li> <a href="#"> <img src="#"></a></li>
<ul>

$("ul.footer-8-flickr li a img").append("<div class='overlay'><p>Content</p></div>");

May be I am missing something.

4 Answers 4

5

Use after instead of append .

Take a look at

Fiddle

<ul class="footer-8-flickr">
    <li> <a href="#"> <img src="#"/></a>
    </li>
    <li> <a href="#"> <img src="#"/></a>
    </li>
    <li> <a href="#"> <img src="#"/></a>
    </li>
    <li> <a href="#"> <img src="#"/></a>
    </li>
    <li> <a href="#"> <img src="#"/></a>
    </li>
    <li> <a href="#"> <img src="#"/></a>
    </li>
    <li> <a href="#"> <img src="#"/></a>
    </li>
    <li> <a href="#"> <img src="#"/></a>
    </li>
</ul>
Sign up to request clarification or add additional context in comments.

2 Comments

<img> is valid HTML5 closing tag.
@RahilWazir: Thanks for correcting, even I was a bit confused initially
2

You can't insert an element inside an img element, instead you can insert it after the img element as the next sibling

$("ul.footer-8-flickr li a img").after("<div class='overlay'><p>Content</p></div>");

Demo: Fiddle

You can use .after() to do this.

Comments

2

You cannot Insert content in an img element.

Try this

$("ul.footer-8-flickr li a").append("<div class='overlay'><p>Content</p></div>");

It'll add div after img tag as a sibling.

1 Comment

I wanted it to insert it after img
2

You can't append in img element because it is self closing tag instead append it to a element.

$("ul.footer-8-flickr li a").append("<div class='overlay'><p>Content</p></div>");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.