Reputation: 25
This keeps on throwing an error, is there a way to put two or more classes in the same "bracket" when one is a var?
$("#test a").click(function(){
var $color = $(this, "p").text()
$("#left-part").removeClass().addClass("ClassnameX" $color);
});
Upvotes: 1
Views: 35
Reputation: 133453
There is syntax error in the .addClass("$color" $color)
Directly pass the variable to your method
$("#left-part").removeClass().addClass("$color").addClass($color);
OR, using string concatenation
$("#left-part").removeClass().addClass("$color " + $color);
Upvotes: 1