Getting and setting check boxes with jQuery

Getting and setting check boxes in jQuery is a lot easier than setting radio buttons and we can thank the “prop” function for that.

Here is the HTML, notice each check box has its own Id, that is the key so the jQuery selector can get at the “checked” property:

Screen Shot 2013-11-25 at 10.46.49 PM

Getting the value is a single line call and it can be stored in a boolean:

pillar_buy = $('#screen_pillar_buy').prop( "checked");

Setting is just as easy:

$('#screen_pillar_buy').prop( "checked", pillar_buy );

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s