Skip to content Skip to sidebar Skip to footer

Div Display If Block Jquery

i am trying trying to find out if a div style display is block then do something here is an e.g this is just a guess i am tryng to do it in jquery if('#toshow':'display' == 'block

Solution 1:

So you want to distinguish between display: block and display: none ? If so, you can better use the is() function in combination with the :visible selector for this:

if ($('#toshow').is(':visible')) {

} else {

}

This works regardless of if you used display: block, or display: inline, or display: inline-block.

Solution 2:

You need to use the css function.

if($("#toshow").css("display") == "block"){

}else{

}

Solution 3:

$(document).ready(function(){
    if ($('#toshow').css('display') == 'block') {
        // Do something.
    } else {
        // Do something else.
    }
});

Should do the trick.

Solution 4:

Don't forget your :visible selector.

if ($("#toshow:visible").length) {
  // it's visible
} else {
  // it's not visible
}

Solution 5:

This option worked perfectly. I am Brazilian and I had to translate the text, but when I saw the code I immediately saw that it was the correct option.

functionreversoObjeto() {
  $('#janela').fadeToggle(500, function(e) {
    if ($("#janela").css("display") == "none") {
      alert("Janela Apagou!");
    } else {
      alert("Janela Acendeu!");
    }
  })
}

Post a Comment for "Div Display If Block Jquery"