Reputation: 1201
I'm trying to add images dynamically in a div element. So I have a block like that
<div id="gallery" >
<img src="images/slide1.jpg" alt="Slide 1 />
<img src="images/slide2.jpg" alt="Slide 2 />
<img src="images/slide3.jpg" alt="Slide 3 />
<img src="images/slide4.jpg" alt="Slide 4 />
</div>
The idea is to insert image dynamically after the first image so my new image goes after the first image. I tried appendTo, append , after, insertAfter .
Do you have any ideas ? Thanks in advance :)
Upvotes: 2
Views: 5256
Reputation: 1201
There is the answer to my problem, I resolved it by using this line :
$image.insertBefore("#container > img:last");
I remember that I add my pictures by the end and no the beginning of the container element.
Thanks again.
Upvotes: 0
Reputation: 47956
You have some malformed HTML there- I'm going to assume it was a mistake when copying the code...
Perhaps this will help -
$('<img src="foo.jpg" />').insertAfter("#gallery > img:first");
If you want to use the insertAfter()
function, you have to be sure that you have selected the correct element. In this case it is
img
tag - :first
>
gallery
. - $("#gallery")
Upvotes: 6