-1

Problem : this is not working!!

HTML

<div id="circle1" class="circle"></div>
<div id="circle2" class="circle"></div>
<div id="circle3" class="circle"></div> 

JS

var circle = document.getElementsByClassName('circle');
        circle.onmouseover = function(){  /* This is not working */
           document.write("Hovering over one of the element that contains circle class");
        }
  • 3
    `getElementsByClassName()` provides a list. You need to iterate it (for loop) and assign the event to each element of it. – Lain May 09 '18 at 14:26
  • I'd say the dupe target is more of an answer to their problem than a dupe.... – Feathercrown May 09 '18 at 14:37

1 Answers1

-2
var circle = document.getElementsByClassName("circle");
for (i = 0; i < circle.length; i++) {
    circle[i].onmouseover = function(){  /* This is not working */
           document.write("Hovering over one of the element that contains circle class");
        }
}

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_getelementsbyclassname_loop

jom
  • 56
  • 1
  • 8