Answer the question
In order to leave comments, you need to log in
How to store the value of a class into a variable?
How can the content of an element's class attribute be stored into a variable if the element has multiple classes?
example
The task before me is this: when hovering over an element, save the value of the attribute into a temporary variable, change the classes, and after removing the hover, return the classes from the variable to their original place. The problem is that I do not know in advance what classes will be there.
I tried this way:
var temp1 = banner.attr('class');
banner.removeClass().addClass("red");
banner.attr(temp1);
but it didn't work (it can be seen in the example)
How would it be done correctly?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question