I would like to add dynamically using Jquery a rule to an existing class but that is not attributed to an HTML element until the user clicks a button.
I tried :
$('.show-toggle').css("max-height", width * 0.5);
as suggested in How to add property to existing class but I think it does not work because the class is not active at first.
HTML
<div id ="toggler"></div>
<div id = "toogle" class="hide-toggle">
CSS
.hide-toggle {
display:none
}
.show-toggle {
display : block;
}
JS (with Jquery)
$('#toggler').click(function () {
var width = $(window).width();
$('.show-toggle').css("max-height", width * 0.5);
$("#toggle").toggleClass('hide-toggle').toggleClass('show-toggle');
});