Adding classes to javascript onhover code



  • Currently I, in my page, have an external script, that causes the text within the div "contact" to change color depending on which "item" element is hovered. Now I wish that it is not only the "contact div, that changes color but also the menu div and the curriculum div , as well as any other div, that I might feel like adding later on. I have tried to change my current javascript in order to do so, by adding another let variable and including that in the script. However Nothing has worked up untill this point. I am currently studying on my javascript, to be able to make these changes. But maybe someone could tell how this is done in the cleanest way possible?

    Here's a codepen


    refresh page if you can't see the codepen above



  • Hey @cthornval

    How about doing the same thing that you have done to the #contact element:

      let color = $target.css('color');
      $('#contact').css('color', color);
    

    Now just add any other element that you want to change color on. If its a set of elements use class name instead of id. So something like:

      $('.element_class').css('color', color);
    

    Hope that helps.



  • Hey @cthornval
    Codepen pulls up a 404 error. Do you mind re-sharing your codepen?



  • Hey Avan

    Does this one work for you?



    refresh page if you can't see the codepen above



  • Hey @cthornval

    How about doing the same thing that you have done to the #contact element:

      let color = $target.css('color');
      $('#contact').css('color', color);
    

    Now just add any other element that you want to change color on. If its a set of elements use class name instead of id. So something like:

      $('.element_class').css('color', color);
    

    Hope that helps.



  • Hey Avan! thanl you so much it worked!


Log in to reply