I am using jquery to to find the element on the page with display set to none and return it's id in a variable. My attempt is below:
$(".galleryitem[display='none']").this
Can someone tell me where I am going wrong...
I don't think that you need to add :hidden
psuedo selector. The following will give you the id of selector irrespective of whether it is hidden or not.
var elementId = $(".galleryitem").attr("id");
but if you add it will be bit faster-
var elementId = $(".galleryitem:hidden").attr("id");
$(".galleryitem:hidden").attr("id");
Since jQuery 1.3.2, an element is visible if its browser-reported offsetWidth or offsetHeight is greater than 0. What does this change mean? It means that if your element’s CSS display is “none”, or any of its parent/ancestor element’s display is “none”, or if the element’s width is 0 and the element’s height is 0 then an element will be reported as hidden.
Example:
This means the .galleryitem element is recognized as hidden only if the parrent has display: none style:
var elementId = $(".parent .galleryitem:hidden").attr("id");
or
var elementId = $(".galleryitem:hidden").attr("id");
You can choose the example that works best for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With