开发者

Get photo number from id?

开发者 https://www.devze.com 2023-03-09 10:15 出处:网络
I have a bunch of photos in an array. <div> <img id=\"photo1\"> <img id=\"photo2\"> <img id=\"photo3\"&开发者_开发知识库gt;

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

精彩评论

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