I need to hide a div that has a certain string in it, using contains.. but jQuery is hiding all div’s that are parents of the target div too !
$("div:contains('user_notifications')").css("display","none")
how do I tell jQuery to just match the div that actually contains that string?
Thanks
Edit:
here’s the inner div that contains the string I want to match..
<div class="group" style="display: block;">
<input type="hidden" value="0" name="user[notification_options[new_reply]]" style="display: block;">
<input type="checkbox" value="1" name="user[notification_options[new_reply]]" id="user_notification_options[new_reply]" checked="checked" style="display: block;">
Request help from system admin
</div>
Assuming the div doesn’t have divs that are siblings to the text, you can do this:
This uses
:not()to get the opposite of:has()to only select<div>elements that don’t contain other<div>elements, eliminating the parents. Also I’m using.hide()here as a simplerdisplay: none;, in case you want to show it later.