I am toggling (.red) class via Jquery on a button click. And when the element has the class red I need to give it a margin-top (say a 50px) dynamically via JQuery and not in the class by default. The toggling works fine but not the adding of Margin Top: Code Below with link to fiddle. What am I missing?
$('button').click(function() {
$('.demo').toggleClass('red');
$('.red').css('margin-top','10px');
});
[Fiddle] http://jsfiddle.net/vineetgnair/wb3jd3vn/1/
Thank you all.
$.('red')means: find all HTML elements with the id "red" and add an style attribut to them (with "margin-top: 10px").