Difference between jQuery .hide() and .css(“display”, “none”)

后端 未结 7 1107
既然无缘
既然无缘 2020-12-12 14:33

Is there any difference between

jQuery(\'#id\').show() and jQuery(\'#id\').css(\"display\",\"block\")

and

jQuery(\'#id\').         


        
7条回答
  •  执念已碎
    2020-12-12 15:10

    Yes there is a difference in the performance of both: jQuery('#id').show() is slower than jQuery('#id').css("display","block") as in former case extra work is to be done for retrieving the initial state from the jquery cache as display is not a binary attribute it can be inline,block,none,table, etc. similar is the case with hide() method.

    See: http://jsperf.com/show-vs-addclass

提交回复
热议问题