Retreive value stored in array with jquery index
Posted
by
Dustin
on Stack Overflow
See other posts from Stack Overflow
or by Dustin
Published on 2014-06-04T21:19:27Z
Indexed on
2014/06/04
21:24 UTC
Read the original article
Hit count: 163
I am trying to retreive the stored value (div id) of an index stored in var "current" when it's div is clicked, so I can use it in a function to iterate through to the next index later. I want to store this stored value in a var so I can use it in a div show/hide function.
my html is quite simple:
<div class="gallerypreview" id="1"></div>
<div class="gallerypreview" id="2"></div>
<div class="gallerypreview" id="3"></div>
my javascript is something like this:
var images = new Array();
$(document).ready( function(){
$('.gallerypreview').each(function() {
images.push($(this).attr("id"));
});
$('.gallerypreview').click(function() {
var current = $('.gallerypreview').index(this);
});
});
how would I go about retrieving the div id from this clicked div? nothing I have tried has worked. I can get the index # fine, but I cannot find the value of the index using any functions that utilize the index # yet.
© Stack Overflow or respective owner