Kasim Jasarevic
Kasim Jasarevic

Reputation: 79

Jquery selector can find hidden element ( display: none;), how to disable this case?

I have Html code

<div id="demo" style="display:none;">Test demo</div>

and javascript:

$("#demo");

It will be selected, but I want to div with id = "demo", can not be selected because it's hidden.

Thank's

Upvotes: 1

Views: 3867

Answers (2)

Himanshu dua
Himanshu dua

Reputation: 2523

For selecting hidden use $(':hidden#demo')

For selecting Visible use $(':visible#demo')

Upvotes: 0

Michael Coker
Michael Coker

Reputation: 53709

If I understand correctly and you only want to select #demo if it's not hidden, use $('#demo:visible'). Some helpful resources are https://api.jquery.com/visible-selector/ and https://api.jquery.com/hidden-selector/

Upvotes: 5

Related Questions