Reputation: 563
part of function :
function __openSettingsPage(addonName, targetItem) {
$("#prev-selected").className="addons-listitem"; //error
$("#prev-selected").removeAttr("id");
targetItem.className="addons-listitem-cursor"; //ok
targetItem.id="prev-selected";
};
part of markup :
for (var i in __addons) {
htmlDiv+="<DIV class='addons-listitem'
onclick='__openSettingsPage(\"" + __addons[i] + "\", this);'>
...
I need to change background-color of <div>
with class addons-listitem
in function when I click on it. But there are many other <div>
with class addons-listitem
and previously changed <div>
which recover its background color when click on another <div>
. Now, this code is changes all background color and can't able to recover. There must be only one <div>
which change background at the same time and it's important to change class name because all css styles must be in var css= "";
Upvotes: 0
Views: 1506
Reputation: 133403
You can use .addClass() and .removeClass()
$("#prev-selected").addClass("addons-listitem")
If you want to remove all class and add a class use
$("#prev-selected").removeClass().addClass("addons-listitem")
Upvotes: 1