Sunday, April 3, 2011

Problem with jquery handling checkboxes in IE8

I am using jquery to locate all the checkboxes in a table column that are checked. For that purpose I am using the following code:

        $("input[type=checkbox][checked]").each(function() {

             //Do Stuff

        });

This works fine in Firefox 3 but does not work in IE8 or Safari. Can anyone explain why and/or provide a workaround?

EDIT: I'm using jQuery v1.3.2

From stackoverflow
  • try $("input[type=checkbox]:checked").each...

    Edit or even sweeter: $("input:checkbox:checked").each...

    That works for me in IE8.

    Paolo Bergantino : Fixed your answer, :checkbox alone is not recommended...
    peirix : thank you, good sir (:
  • Try this

     $("input:checked").click(function(){
       alert('abc');    
          }) ;
    
  • A workaround:

    $("input:checked").each(function() {
        //Do Stuff
    });
    
    peirix : this would hit radio buttons as well, though...

0 comments:

Post a Comment