check and uncheck checkbox using JQuery.

Sep 27, 2013, by admin

In this post, you will learn how to check and uncheck checkbox using JQuery.

Example html form

<form>
    <input type=“checkbox” name=“city” id=“city” value=“Newyork” />
    </form>

check and uncheck checkbox using JQuery

There are several ways to check and uncheck checkbox with jQuery. The element attribute will return true if it’s checked or false if it’s not.

Below is the example code of JQuery to check a checkbox:

$(‘#city’).attr(‘checked’, true);

Use below code  to if you have not set element id

$(‘input[name=city]‘).attr(‘checked’, true);

and like so to uncheck the checkbox:

$(‘#city’).attr(‘checked’, false);

or

$(‘input[name=city]‘).attr(‘checked’, false);

Hope this post will help you to get more updates like the page Bugtreat Technologies