In an HTML structure of :
<div class="someclass" tabindex="0" aria-describedby="my-specified-action my-one-name">
<div class="someclass" tabindex="1" aria-describedby="my-specified-action my-two-name">
<div class="someclass" tabindex="2" aria-describedby="my-specified-action my-three-name">
<div class="someclass" tabindex="3" aria-describedby="my-specified-action my-four-name">
<div class="someclass" tabindex="3" aria-describedby="my-specified-action my-five-name">
I need to hide all elements that has an attribute aria-describedby
containing my value ( for example four
), but leave all others untouched.
jQuery('div[aria-describedby*="four"]').hide()
of course, if I will do :
jQuery('div:not([aria-describedby*="four"])').hide()
it will hide ALL elements ( also the ones containing my target ..)
for some reason, this is not working for me ,..
jQuery('div:not([aria-describedby^="four"])').hide()
what am I doing wrong ??
In an HTML structure of :
<div class="someclass" tabindex="0" aria-describedby="my-specified-action my-one-name">
<div class="someclass" tabindex="1" aria-describedby="my-specified-action my-two-name">
<div class="someclass" tabindex="2" aria-describedby="my-specified-action my-three-name">
<div class="someclass" tabindex="3" aria-describedby="my-specified-action my-four-name">
<div class="someclass" tabindex="3" aria-describedby="my-specified-action my-five-name">
I need to hide all elements that has an attribute aria-describedby
containing my value ( for example four
), but leave all others untouched.
jQuery('div[aria-describedby*="four"]').hide()
of course, if I will do :
jQuery('div:not([aria-describedby*="four"])').hide()
it will hide ALL elements ( also the ones containing my target ..)
for some reason, this is not working for me ,..
jQuery('div:not([aria-describedby^="four"])').hide()
what am I doing wrong ??
Share Improve this question asked Feb 22, 2014 at 5:39 Obmerk KronenObmerk Kronen 16k17 gold badges70 silver badges107 bronze badges 8-
because there is no attribute value starting with
four
– Arun P Johny Commented Feb 22, 2014 at 5:42 - your second code is fine does not hide all elements - jsfiddle/arunpjohny/4cdak/1 – Arun P Johny Commented Feb 22, 2014 at 5:43
- first one also is fine - jsfiddle/arunpjohny/4cdak/2 – Arun P Johny Commented Feb 22, 2014 at 5:44
-
isnt´s the
*
stands forcontaining
? ( sorry, I am really bad with anything that is not PHP ) – Obmerk Kronen Commented Feb 22, 2014 at 5:44 - 1 Read Attribute Starts With Selector name^="value" – Tushar Gupta - curioustushar Commented Feb 22, 2014 at 5:46
1 Answer
Reset to default 5Your problem is not the attribute selector, it is the target element selector.
You are hiding all div elements whose aria-describedby
attribute does not contain four
, instead you need to fine tune the selector to target only those element you want. In your case since all the div's share the class someclass
use it like
jQuery('div.someclass:not([aria-describedby*="four"])').hide()
Demo: Fiddle