jQuery check and uncheck a checkbox
In my previous post, you had learned how to set and get form element values using JQuery.
As we know that jQuery is a Javascript framework which simplify Javascript coding complexity and also fixed cross browser issues. 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);
Follow @phpzag

I have read your blog and i got a very useful and knowledgeable information from your blog.its really a very nice article.You have done a great job .
Thank you so much for sharing.
I truly enjoy examining on this website , it contains superb blog posts. “The secret of eternal youth is arrested development.” by Alice Roosevelt Longworth.