E
E
Eugene Stack2016-02-08 01:32:02
css
Eugene Stack, 2016-02-08 01:32:02

How to make it on pure js so that when you hover over 1 element, the rest have the same changes?

There is a hamburger laid out by divs 8a5dd9724de44ee0a890a9afec6fd2d5.png
and you need to write a js script that will change the color to red for all 3 at the same time when you hover over any of them with the mouse 8832ae3fa9a84e99b5b1694c622bcc3e.png
. You can’t use any jquery-type frameworks, only pure js and css.
My attempts were unsuccessful, and this is 9 hours of man time, that's why I came to you so that someone smart would call me stupid and tell me how to do it in a couple of minutes, thanks in advance :)

<div class="menu">
            <div></div>
            <div></div>
            <div></div>
        </div>

.menu {
    float: right;
    padding: 8px 20px 0 0;
}
.menu div{
    border-radius: 4px;
    height: 13px;
    width: 66px;
    background-color: white;
    margin-bottom: 8px;
}

var x = document.querySelectorAll(".menu > div");
        x.addEventListener("onmouseover", myFunction);
        function myFunction() {
            document.querySelectorAll(".menu > div").style.backgroundColor = "red";
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2016-02-08
@Gared

For example:
we find the menu on the page, find these "pieces of a hamburger", on each of them we hang the handler
https://jsfiddle.net/tke4bx2w/
even easier and without js. It is enough to write in css .menu:hover https://jsfiddle.net/tke4bx2w/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question