locked
How to remove class and add another class to a div, when i hover on another div RRS feed

  • Question

  • User1991482975 posted

    Hi,

    i have the following div with class : _style_2VKbTR and data-reactid="95":

    <div role="navigation" aria-label="Passagers" class="_style_2VKbTR" data-reactid="95"><a class="_style_3Hdqj8" href="/fr/ride/"><!-- react-text: 1154 -->Passagers<!-- /react-text --></a><div></div></div>

    when i hover on it (knowing the data-reactid="95" because i will have other link same as but with different data-reactid), with jquery i would love to replace

    the class of the div with class _style_4iw4w9 with this other class _style_3CzhLn

    and when i go out of this div with now class _style_3CzhLn i nees to go back to the previous class _style_4iw4w9

    how to achive thsi with jquery?

    thanks

    Friday, April 6, 2018 2:17 PM

All replies

  • User-369506445 posted

    hi

    please try below code :

    <style>
        ._style_2VKbTR {
            color: red;
        }
        .style_3Hdqj8 {
            color: gray;
        }
        ._style_4iw4w9 {
            font-weight: 900;
        }
    </style>
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" language="javascript">
        $("div").mouseover(function () {
            $(this).removeClass();
            $(this).addClass("_style_4iw4w9");
            $(this).addClass("_style_2VKbTR");
        });
        $("div").mouseleave(function () {
            $(this).removeClass();
            $(this).addClass("_style_3CzhLn");
        });
    </script>
    
    <div role="navigation" aria-label="Passagers" class="_style_2VKbTR" data-reactid="95">
        <a class="style_3Hdqj8" href="#">test</a>
        <div></div>
    </div>

    Friday, April 6, 2018 3:11 PM
  • User1991482975 posted

    Hi Vahid,

    thanks for your answer...

    the problem is tha i need to point the function onclik using the Class name and the data-reactid="95"

    So i need to check the div which contains both.. and aply the function..  add & remove class to another div with another class name and data-reactid=23

    thanks in advance for your help

    Saturday, April 7, 2018 6:50 AM
  • User1400794712 posted

    the problem is tha i need to point the function onclik using the Class name and the data-reactid="95"

    Do you mean that you need to apply click function to the div which contains both the Class name and the data-reactid="95"?

    We can use "._style_2VKbTR[data-reactid='95']" to get the specific div. 

    $("body").on("click", "._style_2VKbTR[data-reactid='95']", function () {
        alert("s");
    })

    What's problem with it? Could you post a detailed explanation? Then, I can understand your requirement better.

    Best Regards,

    Daisy

    Wednesday, April 11, 2018 2:41 AM