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

后端 未结 7 1624
天涯浪人
天涯浪人 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条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 23:39

    They are the same thing. .hide() calls a jQuery function and allows you to add a callback function to it. So, with .hide() you can add an animation for instance.

    .css("display","none") changes the attribute of the element to display:none. It is the same as if you do the following in JavaScript:

    document.getElementById('elementId').style.display = 'none';
    

    The .hide() function obviously takes more time to run as it checks for callback functions, speed, etc...

提交回复
热议问题