开发者

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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜