How can I get the class of a hidden element using JQuery? -
this must possible. see sorts of answers how class of div
etc. here doing:
var $outmap = $('img').not(':hidden'); alert($outmap.attr("class"));
it comes undefined
. know $outmap valid because can use make said hidden element .fadeout
want retrieve class of element. came above code after trying:
alert($('img').not(':hidden').attr("class"));
i sure doing same thing don't know else try.
the problem appears while jquery's selectors return number of elements found, attr
function operates when there's single element.
to illustrate let's have page 5 images (doesn't matter if hidden or visible). if $('img')
you'll 5 results, , calling .attr('class')
returns undefined
.
however, if select single image, selecting id
attribute, .attr('class')
work: $('#some-image-id').attr('class')
give class.
if need class each of several images you'll need iterate, perhaps using jquery's .each
function:
$('img:hidden').each(function(n, image) { alert($(image).attr('class')); });
(note n
paramter number incremented each time through loop.)
Comments
Post a Comment