How to tell javascript to do nothing?

I have a small piece of code, for example:

$("div.footerMenu li").click( function () { $("div.onScreen").hide(); $(this).children("div.onScreen").fadeIn('fast'); },function(){ $("div.onScreen").hide(); });//click 

And when I click on <li> , the div.onScreen displays well, but when I click on this div, I just found that the functions are hidden and displayed again, but I do not want it to execute this function again. So my question is: how can I somehow "separate / exclude / hide" this div from Javascript?

update:

The fact is that with the help of this method and with others with .one () the rest of the menu does not work. There is a website with a problem here . I want this div to appear there when I click on it, but when I click on their <li> elements, I want other divs (submenus) to be displayed (warning - large images on this site).

html looks like this:

 <div class="footerMenu"> <ul> <li>HOME<div class="onScreen"><div style="padding:50px;"><img src="fillTxt.png"></div></div></li> <li>PLENER<div class="onScreen"> <div style="padding:50px;"><img src="fillTxt2.png"></div></div> </li> <li>STUDIO<div class="onScreen"> <div style="padding:50px;"><img src="fillTxt.png"></div></div> </li> <li>INNE<div class="onScreen"> <div style="padding:50px;"><img src="fillTxt2.png"></div></div> </li> </ul> </div> 
+4
source share
3 answers

A simple solution:

 $('div.footerMenu li').unbind('click'); 

But if you have several click handlers on the selector, you can only remove them one at a time. The way to do this is to keep a reference to the function being passed:

 function hideItem() { ...code... //unbind the click event $(this).unbind('click', hideItem); } $('div.footerMenu li').click(hideItem); 
+4
source

If you want to process the event only once, you can use the one () method:

 $("div.footerMenu li").one("click", function() { $("div.onScreen").hide(); $(this).children("div.onScreen").fadeIn("fast"); }); 
+2
source

You can use .one() :

 $("div.footerMenu li").one('click', function(){ things_to_happen_only_once(); // unbinding happens automatically }); 
0
source

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


All Articles