When the user clicks on an image, I want the onClicks on all other images to be disabled until my function has finished.
I currently have this code that disables them:
var eles = document.getElementsByTagName('img');
for (var i=0; i < eles.length; i++)
eles[i].onclick = false;
but I'm not sure how to re enable them. I have tried:
var eles = document.getElementsByTagName('img');
for (var i=0; i < eles.length; i++)
eles[i].onclick = true;
But its not working. anyone have solution for this problem
by setting
eles[i].onclick = false;
you are reassigning theonclick
event tofalse
. setting back to true does not assign it back to the original function. It is probably better to handle the un-assigning in the event function instead.One solution is to save the previous value of onclick and restore it:
Your solution doesn't work because you removed your onClick with onClick = false. After that you need to create the onClick event handler again.
This is probably your way of adding onclick events, I changed it so it should work.
Try adding a function to your onclick as above.
Your onclick function:
This is how you disable your onclicks (your method)
This is how you re-enable them (re-attach function to onClick )
This is a Jquery solution jquery:
Try using unobstructive javascript, by not adding onclick event handlers in the DOM.
When your function is finished just set
function_is_finished
totrue
onclick it suppposed to be pointing to a javascript function. instead of onclick try with.
and at the end of your method back to eles[i].disabled="false"
Basically you're setting the elements'
onclick
tofalse
andtrue
. it's the equivalent of doing something likethen
What you should do is maintaining some variable that you check against to see if you can start the function or not.