- This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
Viewing 9 posts - 1 through 9 (of 9 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Add Class Not Working
When I click on my bootstrap menu link that has id of id=”dashboard” it should add class=”selected” and then makes it change color from css.
How can I make it work correct? http://codepen.io/riwakawebsitedesigns/pen/gbXpPz
Just remove li
from the selector…
$("#dashboard").click(function() {
Your selector is incorrect
$("li #dashboard")
selects the #dashboard
element that is a child of an li
Since there will only be one #dashboard` the below should be adequate.
$("#dashboard")
A minute late but a better answer. :-p
A minute late but a better answer
I had the post ready but held off until I had the Codepen forked.
I’d prefer toggleClass
to addClass
but each to their own.
When I click on id dashboard it disappears menu still need it to stay any idea why disappears
There’s a link inside the li
so that’s also getting clicked so it tries to take you there.
If you make the link a null #
it works…I’ve updated the Codepen above.
What do you want that click to do (other than be ‘selected’)?
On my on my menu when the user returns to the dashboard when click on link will show up. I will be adding a background url image for it I just put color red for testing.
On my on my menu when the user returns to the dashboard when click on link will show up. I will be adding a background url image for it I just put color red for testing.
If the click of the link inside #dashboard
navigates the user to a new page, then the .selected
class will be lost when they return.
Otherwise, it should be fine.