Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to put mouseover and mouseclick on same element

I am using a href tag. I need to open one popup on mouseover and need to open another page on clicking that tag.

I need something like this;

<a href='#'onclick='method1();' onmouseover ='method2();'>SOMETHING</a>

method2() will open a popup. method1() will redirect to another page.

The problem is that when i try to click, popup is opening always (method2 gets called). How to fix this?

like image 370
Mahesh Narayanan Avatar asked Jan 22 '26 07:01

Mahesh Narayanan


1 Answers

There is no way to detect user's intention of clicking or not the link. So, every time user enters the mouse over the link, the popup function will get executed.

You could set a timeout. If user does not click the link in that time limit, the popup will get alerted

$(document).on('mouseenter', '#link', function() {
  setTimeout(function() {
    var that = $(this);
    if (!that.hasClass('clicked')) {
       alert('popup on hover!!');
    }
  }, 1000);
});

$(document).on('click', '#link', function() { 
  var that = $(this);
  that.addClass('clicked');
  alert('clicked!!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a id="link" href="">Link</a>
like image 183
kapantzak Avatar answered Jan 23 '26 19:01

kapantzak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!