Can I use jQuery to change a CSS property for a CSS class, not a matched element?
I am t开发者_如何学Pythonrying to use jQuery to set the margin-left
property for a CSS class.
$('.first_note').css('margin-left',50);
Only one element on my page will ever have the class first_note
.
I need to remove the first_note
class from the element, and apply it to another element. The problem is when I do, the previous first_note still has the margin-left
value of 50, and the new one doesn't.
It's because in that jQuery code I'm applying the css property to the element. What I actually need to do is change the property for the class itself. Is this possible with jQuery?
@Ben, I think in this case I'd do it this way;
- Create a class called say Margin50.
- I'd then set the classes in jQuery accordingly.
So if you have your two elements, the first one uses removeClass for first_note and also the Margin50 and then apply first_note and Margin50 to the next element.
精彩评论