Visibility attribute question

前端 未结 3 1847
挽巷
挽巷 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:01

    Nothing. Just two ways to accomplish the same goal.

    The first will overwrite any existing style settings. If you had:

    It would become:

    The second will add the visibility setting to the existing styles. So:

    Woudl become:

    If there's no style attribute already set, then the two will produce the same end result.

提交回复
热议问题