How to set “style=display:none;” using jQuery's attr method?

后端 未结 8 1628
闹比i
闹比i 2020-12-24 12:04

Following is the form with id msform that I want to apply style=\"display:none\" attribute to.

8条回答
  •  独厮守ぢ
    2020-12-24 12:55

    Why not just use $('#msform').hide()? Behind the scene jQuery's 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.

提交回复
热议问题