I have an html structure like following
<div class="fieldset-wrapper">
<div data-index="one">...</div>
<div data-index="two">...</div>
<div data-index="three">...</div>
<div data-index="four">...</div>
</div>
I want to hide only the div elements with ‘data-index’ attribute value ‘one’ & ‘three’.
I have tried the following, but it is not working.
$('.fieldset-wrapper div:not([data-index="one"]):not([data-index="three"])').hide();
How should I do this ?
2
Answers
You have to use the filter method.
First, select all the div then filter the divs which you want to hide then call the hide method
Alternatively, you can do this as well.
No need to filter – you can add the container as context if you want to be more specific
I want to hide only the div elements with ‘data-index’ attribute value ‘one’ & ‘three’