menu

arrow_back How to save the value of a class variable?

by
0 votes
How can I save the contents of the class attribute of the element in a variable if the element has multiple classes?
example
My objective is this: with the tip of the element, save the value of the attribute in a temporary variable, change classes, and after removing the interferences to return classes from a variable to its original place. The problem is that I don't know in advance what there will be classes.
I tried this way:
var temp1 = banner.attr('class')%3B
banner.removeClass().addClass("red")%3B
banner.attr(temp1)%3B
but not earned (example seen)

I don't know how to do?

1 Answer

by
 
Best answer
0 votes
var c = $('#item').attr('class');
$('#item').attr('class', c);