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

Home Forums JavaScript Trying to add another addClass(); when element is clicked in jQuery

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #41488

    See how when you hover over the boxes, they turn blue; as well as the rounded rectangle with the number in it. Then, if you click “Google”, a menu drops down and the box on top stays blue, but the rounded rectangle with the number inside does not.

    (P.S. sorry for the weird id and class names)


    I think you’re going about it wrong. Instead of changing `.val-google` to `.active-google` you could just focus on the parent class/hover state. Change all of the values to just have a common class like ‘.value’, then you you can change the style of it based on its parent:

    .li:hover .value, .this-item-is-dropped-down .value {
    /* styles */

    In fact, you should be removing the majority of jQuery that you’re using. Let’s see if I can whip up a quick Pen…


    Ohh, I see! I just started learning jQuery and implementing it into simple projects like this.


    I removed a bunch of code:

    It’s not perfect, but it should show you how you can continue.

    You also had some bad practices going on with your list items by having the `` wrapping the `

  • `, it should be the other way around.

@TheDoc Hey, the JS was accidentally deleted when I tried to copy it, can you do that part again, please? Thank you so much for you time helping me!


If you go to the link I posted above it should be there.

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