Get photo number from id?
I have a bunch of photos in an array.
<div>
<img id="photo1">
<img id="photo2">
<img id="photo3"&开发者_开发知识库gt;
<img id="photo4">
</div>
I have a slideshow. My slideshow works by showing the photo number based in the div.. i.e.
var photos = $('div img');
$(photos[0]).show();
Is there a quick way to get img position in the div? So #photo1 would be 0, #photo4 would be 3. If not.. what is the most efficient way to get the img id and return (number - 1)?
you should use eq method where you have to pass index.
photos.eq(0).show()
To get the index of the photo3
use $("#photo3").index()
.
to find image id you can try this
var imgID = $('img').attr('id');
精彩评论