When using jQuery to change the css of an element, I've noticed that it can remove some previously specified css rules for that element.
For example,
.className, .className2, etc... {
background-color: black;
color : silver;
}
.className:hover, .className2:hover, etc... {
background-color: gray;
color : white;
}
In my case, when a user clicks on an element, I want the background to permanently change to indicate it has been clicked. If another sibling element is then clicked, I would like it to revert back to its original css rules and not retain the jQuery-set styles (meaning it loses its rgba background and regains its hover effect).
highlightClicked : function (el) {
el.css({
"background-color" : "rgba(70, 70, 70, 0.7)",
"color" : "white"
});
$('#parentElement > span').each(function () {
$($(this)).not(el).css({
"background-color" : "rgba(70, 70, 70, 0.0)",
"color" : "gray"
});
});
},
However, it appears that the jquery .css function removes these original css rules.
Is there a way to preserve them?