javascript - Jquery get image id of next element -


I have a list of images, I try to use Jquery to find the next image ID from the current element I am But I can not seem to work for Jquery

  & lt; Div class = "grid" style = "position: relative;" & Gt; & Lt; Div class = "preview" & gt; & Lt; Img src = "1.jpg" id = "175" alt = "" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "grid" style = "position: relative;" & Gt; & Lt; Div class = "preview" & gt; & Lt; Img src = "2.jpg" id = "176" alt = "" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "grid" style = "position: relative;" & Gt; & Lt; Div class = "preview" & gt; & Lt; Img src = "3.jpg" id = "177" alt = "" & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

javascript

  var childId = 6; $ (".grid") .click (function () {var image = $ (this) .find ("img"); var imageId = image.attr ("id") show_image (imageId, childId);}); The function show_image (imageId, childId) {// is required to get the next image ID in the group for the next button, but the code below undefined var next image = $ (".grid .preview #" + imageId) .next ("img") .attr ("id"); }  

You can not use directly in .next () This case, because the images are not siblings for each other's use,

  var nextImageId = $ ("#" + imageId) .closest (' Grid '). Next ("grid") appears ('img') attr ("id") ..  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -