简体   繁体   中英

onmouseover event javascript links

I am trying to have an event occur anytime you hover over any link from a webpage.

I think I need to use the mouseover event but I dont know how I can to do this.

I just want it to recognize it, and give me an alert. Thanks

Array.prototype.forEach.call(document.getElementsByTagName('a'),
    function(el) {
        console.log(el);
        el.addEventListener("mouseover", function() {
          alert(el);
        });
    });

if you can use jQuery, it's even easier:

$('a').on("mouseover", function(e) {
  alert(e.target);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM