a53-416
a53-416

Reputation: 3935

Hover doesn't work but click does

Update: Broken on Chrome only, Safari seems to work fine. Maybe it's something in my star.

I have HTML that looks like this

  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>
  <div class="star"></div>

I want to trigger an event on hover. So i have code that looks like this:

$(document).ready(function(){ 
  $('.star').each(function(){
    $(this).hover(function(){
      console.log('hover');
    });
  });
});

I even tried this:

 $(".star").hover(function(){ 
    console.log("hover triggered"); 
  });

I have tried multiple variations of this code with no success. THe hover code only works when I click on star, but not when I hover. Please help as I'm really lost as to why this isn't working. When I try this on JS Fiddle, it works, but my page isn't set up that much differently. WHy would it work on click but not on hover, when then trigger is hover?

Upvotes: 0

Views: 1263

Answers (2)

Dave Mulder
Dave Mulder

Reputation: 116

I was having the same problem. Turns out I had previously been using Chrome's Developer Tools to emulate a touch screen, which screwed with the hover event.

Upvotes: 4

Rafael Moni
Rafael Moni

Reputation: 666

Try this..

$(function(){ 
    $('.star').hover(function(){
        console.log('hover');
    });
});

Upvotes: 0

Related Questions