I have a div that has an onlcick event. Now when I click div, I want to change my onlick function using the .click jquery attribute. I can change it dynamically, but when I apply it, a new event is also fired. Is there any work to prevent the new one from being launched, but just applied to the div with the new function? This is what i am trying to do
i has a div
<script type="text/javascript">
function testMe(data)
{
alert(data);
$('#testMe').unbind('click');
$('#testMe').click(function(){ testMe('2'); });
}
</script>
<div id='testMe' onclick='testMe(1)' >click on me, I will disappear.</div>
when I execute the code above, I still get the value 1 ohm warning field THANKS EveryOne
I also tried the code below, but it does not work for me
function testMe(data)
{
alert(data);
$('#testMe').unbind('click');
$('#testMe').click( testMe(2) );
}
Although the code updates the onlick event from 'testMe (1)' to 'testMe (2)', it continuously alerts the value 2. Working around this problem is a traditional JS script code like:
document.getElementById('testMe').onclick = testMe(2) ;
And his work is without warning.