开发者

div display if block jquery

开发者 https://www.devze.com 2022-12-16 12:51 出处:网络
i am t开发者_开发百科rying trying to find out if a div style display is block then do something

i am t开发者_开发百科rying 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"){

 }else{

 }


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.


You need to use the css function.

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

}else{

}


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

Should do the trick.


Don't forget your :visible selector.

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


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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消