jquery compatibility issue for attr()

As of jQuery 1.6 , the .attr() method returns undefined for attributes that have not been set.

 

Example: I want to select/unselect all item checkboxes by check/uncheck a single "selectAll" checkbox

 

Prior to 1.6 works:

              $('#selectAll').click(function(event) {

                     $('.items).attr('checked', $(this).attr('checked'));

              });

 

That's because attr('checked') will return true or false

But now, it will return checked or undefined

 

New code might be

              $('#selectAll').click(function(event) {

                     $('.items).attr('checked', $(this).is(':checked'));

              });

 

你可能感兴趣的:(jquery)