Maria Jane Maria Jane - 3 months ago 54
jQuery Question

remove style attribute using attr jquery

I have this DOM like

<p style="width: 770px;position: relative;left: -2310px;top: 0px;z-index: 999;opacity: 1;">


How to remove JUST the position property? I can't add back those other values as it's dynamic generated by a plugin.

Answer

From JQuery docs

Setting the value of a style property to an empty string — e.g. $('#mydiv').css('color', '') — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's .css() method, or through direct DOM manipulation of the style property. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or element.

$(selector).css("position", "");
Comments