Need to check if the item is hidden

Here is the code:

$(function() { if($('#id').is(':hidden')){ alert('Hidden'); } }); 

It works, but how to check the same for visibility: hidden; opacity: 0; visibility: hidden; opacity: 0; wrapped block with display:none and other ways to hide an element from the screen?

    1 answer 1

     function check(selector) { var cs = [ 'display', 'visibility', 'opacity' ]; var rc= []; for (var i = 0; i < cs.length; i++) { rc.push($(selector).css(cs[i])); } return rc; } check('#foo'); 

    when you call a function, pass the selector that you want to check, the array cs - what you need to check, the array rc - the result, well, then you insert the condition for your task

    • it is easier not to return an array, but true / false - Jean-Claude
    • You essentially did not understand the question. - Rammsteinik
    • What's wrong? There is a check on display, visibility, opacity, to put the necessary conditions, I think it is not a problem, as well as get the returned array with true / false. Check through .is on visibility and opacity is impossible, because the element visually takes place in the body of the document. - 2perca