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

后端 未结 7 1151
既然无缘
既然无缘 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:26

    Difference between show() and css({'display':'block'})

    Assuming you have this at the beginning:

    
    

    when you call:

    $('#thisElement').show();
    

    you will get:

    Foo
    

    while:

    $('#thisElement').css({'display':'block'});
    

    does:

    Foo
    

    so, yes there's a difference.

    Difference between hide() and css({'display':'none'})

    same as above but change these into hide() and display':'none'......

    Another difference When .hide() is called the value of the display property is saved in jQuery's data cache, so when .show() is called, the initial display value is restored!

提交回复
热议问题