Visibility attribute question

前端 未结 3 1848
挽巷
挽巷 2021-02-03 23:17

What is the difference between

$(\"#myid\").attr(\"style\", \"visibility: hidden\")

and

$(\"#myid\").css(\"visibility\", \"hidden\"

3条回答
  •  一向
    一向 (楼主)
    2021-02-04 00:24

    There isn't really any difference. $.css() is just a shortcut method for accessing the css style attribute of a dom element.

    http://api.jquery.com/css/

    EDIT: As justin pointed out, there is a difference in that the .attr() method will overwrite any existing style attributes.

提交回复
热议问题