I am having trouble retrieving elements by style attribute.
I have a ul
with several li
elements and I would like to find the one with the style atribute having a value display:list-item
. I have tried to approach this in several ways, including the following, but I keep getting an empty object. I have no problem with a title attribute. Not sure what I am doing wrong.
$('li[style*=display:list-item]')
HTML:
<ul class="bjqs" style="height: 200px; width: 100%;">
<li class="bjqs-slide" style="height: 200px; width: 100%; display: list-item;">
Your selector is white-space sensitive, given that you have white-space in the attribute, you'll need that in your selector as well:
$('li[style*="display: list-item"]')
The easiest way, which reduces the problems of precisely matching a string, if you're filtering elements according to a particular CSS property, is to use filter()
:
$('li').filter(function(){
return $(this).css('display') === 'list-item';
});
References:
filter()
.Two problems:
""
.Simply change your selector to include this space and wrap it in quotes:
$('li[style*="display: list-item"]')
JSFiddle demo.
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