删除CSS的“顶部"和“左" jQuery的属性 [英] Remove CSS "top" and "left" attributes with jQuery
问题描述
我正在构建一个可拖动的地图,当拖动地图时,该元素将被赋予"left"和"top"属性,并且每个属性的值都应这样...
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...
<div class="map" style="top:200px; left:100px;">Map</div>
我有一个按钮,当我单击时,我想从div的内联样式中删除top和left属性,这对于jquery可能吗?
I have a button that I want to remove the top and left attribute from the inline style on the div when clicked, Is this possible with jquery?
推荐答案
CSS的默认值 top
和 left
是auto
,因此将它们设置为可能等效,具体取决于您要执行的操作:
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');
您还可以选择完全删除style
属性:
You also have the option of wholly removing the style
attribute:
$('.map').removeAttr('style');
但是,如果您使用的是其他jQuery UI组件,则这些组件可能需要不需要删除的内联样式,因此请谨慎行事.
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.
这篇关于删除CSS的“顶部"和“左" jQuery的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!