JQuery live ‘change’ doesn’t work in IE

Posted in JQuery on May 4th, 2010 by taswar

So was having issues as in why does my checkbox doesn’t work in IE when I do

?View Code JAVASCRIPT
1
2
3
  $('.checkbox').live('change', function() {
    alert('Checkbox clicked');
  });

And found out that jquery does not bind live “change” events, I was told that it works in 1.4.2 but for some reason I still was not able to get it working.

The solution that I found was to use the livequery or bind method thus the code would become

?View Code JAVASCRIPT
1
2
3
  $('.checkbox').bind('change', function() {
    alert('Checkbox clicked');
  });

or if you are using Ajax then

?View Code JAVASCRIPT
1
2
3
  $('.checkbox').livequery('change', function() {
    alert('Checkbox clicked');
  });

That should do the trick, remember to add jquery.livequery.js if you are using livequery in your file.

Share

3 Responses

  1. Nitin Says:

    This was helpful.

  2. Sean Bean Says:

    I realize this post is over a year old, but I hope this is helpful to anyone else who stumbles upon it like I did.

    You need to make sure you are in fact setting class=”checkbox” for your checkboxes if you are going to access them with $(“.checkbox”).live(…);

    . If not, you can access them using
    $(“input[type="checkbox"]).live(…);

    Also, using live() is costly compared to other dynamic event handling methods, like bind() or delegate().

  3. taswar Says:

    Yes I agree, but bind does not work in data that is dynamic I would recommend delegate better.

Leave a Comment