I am trying to prevent users from running a function two consecutive times due to a double click. In the code below, I have the click event attached to the image and when the onclick function is called, the first thing i do is remove the click event. Once the function is done, I replace the click event. This works as it should when single clicking, but when double clicking the function gets called twice. Even if the second click comes after the message is logged to the console, it still fires twice. Is there any way to prevent this?
<div id="pre">
<img src="/pics/magnifying_glass_lg.png" id='preloader' onmouseover='style.setProperty("cursor","pointer");' onclick='start_search(this)';>
</div>
function start_search(button){
button.onclick=function(){};
console.log("click is removed");
// stuff goes here
var el = document.getElementById('preloader');
el.onclick=function(){start_search(el)};
}