Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript add removing class on click once and again.

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #33983
    Attila Hajzer
    Participant

    howcome it doesn’t work with .click but it works with hover? it doesn’t make sense. what i want is when you hover over a list item, then there’s the hover color, then when you click i have a div appear (sliding down) then i want the LI #Show to have a yellow background-color then when clicked again the div goes away Display:hidden) and then i want the LI#Show to go back to its regular state. but i canonly get so far. where if the li is clicked once, then the div appears and the li background goes yellow, but once i click it again the div dissappears but the color does not go away.

    https://css-tricks.com/snippets/jquery/addingremoving-class-on-hover/

    #85278
    wolfcry911
    Participant

    what do you have so far?

    #85280
    jamygolden
    Member
    $('#elm').click(function(){
    $(this).toggleClass('active');
    });
    #85308
    clokey2k
    Participant

    I was going to submit a response as I thought I had a good answer. I too did not know of ‘toggleClass()’

    +1 for learning!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.