I'm using sortable, I need to remove the margin-right and not just leave it as 0. I have problems if you use margin-right 0 to sortable. He wins by default margin by jquery. So no use class change, and can not use remove.attr ("style"), because would remove all the CSS.
Asked
Active
Viewed 1.2k times
0
-
would `margin: -1` work? – Pow-Ian May 14 '13 at 13:42
-
I'm using jquery sortable, elements change position. – Giovane May 14 '13 at 13:45
-
Try the solution in this related thread: http://stackoverflow.com/questions/5951365/how-to-remove-only-one-style-property-with-jquery – Sean May 14 '13 at 13:52
1 Answers
8
$('selector').css('margin-right', '');

tbleckert
- 3,763
- 4
- 32
- 39
-
1This works if you have jQuery set the margin-right initially but if it is in CSS i.e. `.fred{margin-right:4em; margin-left:6px; border:solid green 1px; display:inline-block;}` it would fail to actually remove and would get set to `4em` in this example. Which is known and documented, see comment on the question. http://jsfiddle.net/e9Y28/ - I tested using Chrome – Mark Schultheiss May 14 '13 at 14:30
-
Well, that's not the case here. If he had set the margin in CSS, then he could just remove it. – tbleckert May 14 '13 at 18:52
-
this code did not work for me. $('selector').css('margin-right', '0px'); did however. In my case the margin was set in a style sheet, on the 'body' selector – 2b77bee6-5445-4c77-b1eb-4df3e5 May 18 '17 at 20:57