jquery - Why unbind event on image is not working -


i have got image on want disable click event , have used unbind event shown below

$('#myimage').unbind("click"); 

but please let me why click event still working ??

this code

$(document).ready(function () {     $('#myimage').unbind("click"); })  $(document).on('click', ' #myimage', function (event) {     alert('i called'); }); 

this fiddle

http://jsfiddle.net/ygbxdspc/5/

the issue in fiddle code block running in document.ready handler (due settings you've chosen) unbind() called before event bound, hence no event removed.

to fix actual problem, need use delegated form of off() method attached delegated event handler using on(), this:

<script>     $(document).ready(function() {         $(document).off('click', '#myimage');     })      $(document).on('click', '#myimage', function(event) {         alert('i called');     }); </script> 

working example

note in settings of fiddle js code set execute 'no wrap - in <head>'


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -