I am dynamically setting the position attr of the element only when the view is out of viewport of the window, in other case default value is set from the css file ,
.css( { "left": (left + 20) + "px", "top": (top+10) + "px" } );
Once the dynamic position is set, I want to remove the position attr alone.
I can remove style attribute it will also my display property of style which is required.
Is there a way to to remove the position attr alone?
To remove an attribute from each tag using jQuery, use the removeAttr() method and use the Universal Selector. Let us see how to use the method to remove all style attribute. Use the universal selector also to select all the elements.
removeProperty() method is used to remove a property from a style of an element. The style of the element is selected by going through the styleSheets array and selecting the cssRule. The removeProperty method can then be specified with the property to be removed.
jQuery position() Method This method returns an object with 2 properties; the top and left positions in pixels.
The removeAttr() method removes one or more attributes from the selected elements.
Perhaps, your best Bet would be to simply put them to their default value. Top and left have the default value "auto". So:
jQuery(selector).css({
'top': 'auto',
'left': 'auto'
})
$(el).css('top', '');
will remove the inline style declaration, reverting back to either what is specified in your stylesheet or the default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With