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.
精彩评论