Remove click event handler - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:die

Description

Remove click event handler

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">
</script>//from   w  ww  .  j ava 2s.  c  om
<script>
function changeSize(){
    $(this).animate({fontSize: "+=3px"});
}

function changeSpacing(){
    $(this).animate({letterSpacing: "+=2px"});
}

$(document).ready(function(){
    $("p").live("click", changeSize);
    $("p").live("click", changeSpacing);
    $("button").click(function(){
        $("p").die("click", changeSize);
    });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>Click any p element to increase size and letterspacing.</p>

<button>Remove the event handler</button><br><br>

</body>
</html>

Related Tutorials