Is it possible to add the onmouseover attribute only once?

Let's say I have a link like:

<a class="link" href="www.rich.com" onmouseover="go(this)">Link</a>

Is there a way to configure the onmouseover event by calling go(this) to fire only once, still using the inline onmouseover=<some code> notation? I want it to be defined inline, not with a JavaScript call.

I currently have this, but this is not what I want:

 $(".link").one('mouseover', function(e) { // do something }); 
+5
source share
3 answers

After that, you can onmouseover binding:

 <a class="link" href="www.rich.com" onmouseover="go(this); this.onmouseover = null;">Link</a> 
+7
source

You can install var, which indicates whether it was running or not ...

 var triggered = false; $(".link").one('mouseover', function(e) { // do something if(!triggered) { triggered = true; // and whatever else you want to do } }); 
-1
source

Alternatively, you can do something like this:

 var check = 0; $(".link").on('mouseover', function(e) { if(check == 0 ){ // do something check = 1; }else { return false; } }); 
-2
source

Source: https://habr.com/ru/post/1232747/


All Articles