Check if checkbox is checked using jQuery 1.11

There is a Mobile Optimized version of this page (AMP). Open Mobile Version.

There is much confusion on the internet when it comes to jQuery and  best practices, this is partly because of large charges between jQuery versions which are easily unnoticed as old methods are usually backwards compatible.

However in the case of checking to see if a checkbox is checked, if you use the older methods in the library you will be faced with huge cross browser incompatibility which will severely affect users who are using the browsers affected.

 

Using jQuery 1.6+

If you are using jQuery 1.6 or newer you should check if a checkbox is checked using the below snippet, the snippet will return TRUE is checked or FALSE if unchecked.

$('#checkbox').prop('checked')

 

 

Using older versions of jQuery

If you are using older versions up to 1.5 you should use the method below, if you are using this method on any version above 1.5 you should change immediately to the code above as you will lose browser compatibility otherwise.

$('#checkbox').attr('checked')

Author: Dean Williams

I'm a Web Developer, Graphics Designer and Gamer, this is my personal site which provides PHP programming advice, hints and tips