0

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= "";

New Alexandria
  • 6,951
  • 4
  • 57
  • 77
mzarb
  • 563
  • 1
  • 4
  • 9

1 Answers1

1

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")
Satpal
  • 132,252
  • 13
  • 159
  • 168