Remove CSS “top” and “left” attributes with jQuery

后端 未结 13 1278
故里飘歌
故里飘歌 2020-12-02 07:07

Im building a draggable map that when the map is dragged the element is given a \'left\' and \'top\' attribute with values for each as so...

13条回答
  •  生来不讨喜
    2020-12-02 08:09

    In my opinion the cleanest way is to remove the property completely from the element's CSSStyleDeclaration, instead of just overwriting it with some kind of null/zero/default value:

    $(".foo").prop("style").removeProperty("top");
    $(".foo").prop("style").removeProperty("left");
    $(".foo").prop("style").removeProperty("background-color");
    

提交回复
热议问题