Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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?
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'
I'm not sure if you're asking for removing a position
HTML attribute, a position
style, or top
and left
styles. In any case, you can remove any attribute with $.removeAttr()
, and you can remove (dynamically assigned) styles with $.css({ styleName: '' })
;
Edit: it seems you want $.css({ position: '' })
, or more likely $.css({ position: 'static' })
, as that is the default value.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.