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

后端 未结 13 1249
故里飘歌
故里飘歌 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:08

    The default values for CSS top and left are auto, so setting them to that might be equivalent depending on what you're trying to do:

    $('.map').css('top', 'auto').css('left', 'auto');
    

    You also have the option of wholly removing the style attribute:

    $('.map').removeAttr('style');
    

    However, if you're using other jQuery UI components, those may require inline styles that you don't want to be removed, so proceed with caution there.

提交回复
热议问题