0

I want to unbind click event but it is not working with live method

<script type="text/javascript">
$(function(){
$('a').live('click',function(){
alert(0)
$(this).unbind('click')
})
})
</script>


<a href="#">click</a>

3 Answers 3

2
$(document).on('click','#a',function(){

//Code here

});

live is depricated..use on() for live()

and use this for unbind

$("p").die("click", foo);
Sign up to request clarification or add additional context in comments.

Comments

2

Use .one instead:

$(document).one('click','a',function(){
   alert(0);       
});

Comments

1

Have a look at the die method: http://api.jquery.com/die/

If you use 1.7:

$("p").live("click", foo); // ... now foo will be called when paragraphs are clicked ...
$("p").die("click", foo); // ... foo will no longer be called.

Indeed deprecated but it depends on the version you are using.

 version deprecated: 1.7, removed: 1.9

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.