JQuery, if any of a certain class is hidden, performs a task, otherwise it performs another task

Is there a way to check if some element (.container) is hidden in the whole document? For example (which does not work properly):

$(".showall").click( function () { if ($(".container").is("hidden")) {perform a task} else {return false;} }); 
+4
source share
2 answers

It looks like you want to check if at least one of the .container elements is .container .

If so, you can use the :hidden selector and check the length property to see how many have been returned.

 $(".showall").click( function () { if ($(".container:hidden").length) // found at least one hidden else // didn't find any hidden }); 

If you want to check if everyone was hidden, use the :visible selector as follows:

 $(".showall").click( function () { if ($(".container:visible").length) // found at least one visible else // didn't find any visible }); 
+6
source

You want to use, this is visible:

 $(".showall").click( function () { if ($('.container').is(":visible") == false) {perform a task} else {return false;} }); 
0
source

Source: https://habr.com/ru/post/1313722/


All Articles