Link to home
Start Free TrialLog in
Avatar of RupertA
RupertAFlag for United Kingdom of Great Britain and Northern Ireland

asked on

removing a class in javascript

Hi, on the css I have two classes as follows...

.list_menu a {
display: block;
padding: 12px 0px;
background: #e1e1e1;
text-decoration: none;
}

.list_menu a:hover {
background: #d4d4d4;
background-repeat:no-repeat;
width:100%;
}

I want to remove them both and add my own Selected state when you click my div, I am using the following javascript function when you click, but it doesn't work, am I referencing the classes wrongly? Thanks.

function addMySelectedState()
{
var nameElem1 = document.getElementById("option1");
nameElem1.classList.remove("list_menu a");
nameElem1.classList.remove("list_menu a:hover");
nameElem1.classList.add("list_menu_selected");
}
ASKER CERTIFIED SOLUTION
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RupertA

ASKER

Hi there, both actually work, I wasn't referring to the classes correctly, which is why it was not working! Thanks.
Avatar of RupertA

ASKER

Thanks!