Difference between jQuery’s .hide() and setting CSS to display: none

后端 未结 7 1646
天涯浪人
天涯浪人 2020-11-30 23:19

Which am I better off doing? .hide() is quicker than writing out .css(\"display\", \"none\"), but what’s the difference and what are both of them a

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 00:02

    To use both is a nice answer; it's not a question of either or.

    The advantage of using both is that the CSS will hide the element immediately when the page loads. The jQuery .hide will flash the element for a quarter of a second then hide it.

    In the case when we want to have the element not shown when the page loads we can use CSS and set display:none & use the jQuery .hide(). If we plan to toggle the element we can use jQuery toggle.

提交回复
热议问题