开发者

finding css display value of a div

开发者 https://www.devze.com 2023-02-16 00:44 出处:网络
I have some divs that have a css display of either \'block\' or \'none\' : $(\"#divMTR\").css(\"display\", \"none\");

I have some divs that have a css display of either 'block' or 'none' :

$("#divMTR").css("display", "none");
$("#divST").css("display", "block");

Is it possible to check wha开发者_如何学编程t the css display value is for a div in JQuery? I would like to check what the value is, and on a certain condition change it.


You can get the value of a CSS proeprty by writing $(...).css('propertyName').

You may also want to write if ($('#divST').is(':visible')) (or :hidden), using jQuery's .is() method (which checks whether an element matches a selector) and the :visible and :hidden pseudo-selectors.


Just use :

alert($("#divMTR").css("display"));

This will return the value instead of modifying it. It works for most Jquery methods.

0

精彩评论

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