[英]How to remove only position(top and left) of Style attr using JQuery?
[英]remove only position relative inline style using jquery
我有內聯樣式
<div class="handle" id="parent4" value="3" size="large" style="position: relative; top: 0px; left: 0px; z-index: 0; cursor: pointer;"></div>
我想使用jQuery刪除上述代碼中的位置相對樣式
<div class="handle" id="parent4" value="3" size="large" style= top: 0px; left: 0px; z-index: 0; cursor: pointer;"></div>
嘗試使用static
覆蓋位置,
$('#parent4').css('position','static');
因為static
是所有div元素的默認位置。
將位置設置為靜態,這是默認值。
要刪除樣式,您可以使用.css(stylename,'')
語法。
$('#parent4').css('position','');
這是要刪除的代碼
(function($)
{
$.fn.removeStyle = function(style)
{
var search = new RegExp(style + '[^;]+;?', 'g');
return this.each(function()
{
$(this).attr('style', function(i, style)
{
return style.replace(search, '');
});
});
};
}(jQuery));
使用這個迷你插件,您可以編寫JS文件
$('#element').removeStyle('position');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.