javascript – How to set style=display:none; using jQuerys attr method?

javascript – How to set style=display:none; using jQuerys attr method?

Why not just use $(#msform).hide()? Behind the scene jQuerys hide and show just set display: none or display: block.

hide() will not change the style if already hidden.

based on the comment below, you are removing all style with removeAttr(style), in which case call hide() immediately after that.

e.g.

$(#msform).removeAttr(style).hide();

The reverse of this is of course show() as in

$(#msform).show();

Or, more interestingly, toggle(), which effective flips between hide() and show() based on the current state.

As an alternative to hide() mentioned in other answers, you can use css() to set the display value explicitly:

$(#msform).css(display,none)

javascript – How to set style=display:none; using jQuerys attr method?

$(document).ready(function(){
var display =  $(#msform).css(display);
    if(display!=none)
    {
        $(#msform).attr(style, display:none);
    }
});

Leave a Reply

Your email address will not be published.