E-Learning

Learn JavaScript – How to Verify if a Checkbox is Checked in jQuery?

 
If you are using jQuery and want to find out if a particular checkbox is checked, inside jQuery there are some fairly straightforward ways to do this. In this article, we will explore some of them, along with some examples.
 

jQuery – checking a checkbox with is ( ‘:checked’)

The first way to check this is by using the function is () in jQuery. It checks if the argument or set of arguments that you stated satisfies the given condition. If so, it returns “true”. If not, it returns “false”.

To use is (), we first need to choose the element and then do the check using the selector :checked, that works with several elements, including checkboxes. Example below:

 

jQuery – checking a checkbox with prop ( ‘:checked’)

Before  jQuery 1.6 the function attr () was used to obtain both attributes as the properties of an element. This creates some confusion, so much so that after jQuery 1.6 a new function, called prop () was designed to verify the property of the element analyzed.

A short explanation about the difference between attributes and properties. Simply put, the attribute can be considered the value declared in the code, as the property is the value when the check is done. If the user changes this value, such happens with a checkbox, for example, what you want is the property of this element. Example using prop ():

Do you know other ways to check if a checkbox is checked using jQuery? Share with us in the comments area at the bottom!

If you want to explore more about jQuery, visit our section of videos! Below are some examples:

You can also follow some of the broadcasters who program in jQuery, as below:

 

checkbox jQuery JavaScript programmingkhaleelsyed

checkbox jQuery JavaScript programmingtoferj

Another cool way to find out interesting things about jQuery is to access our jQuery project page!

About author

About Author Dr. Michael Jurgen Garbade is the founder of LiveEdu.TV, Kyuda, Education Ecosystem. He is future Venture Capitalist, Future Politician and always on the lookout for the Next Big Challenge. Obtained Masters in business administration and physics, and a Ph.D. in finance with professional work experience in high-paced environments at Fortune 500 companies like Amazon and General Electric. Expertize: Python, PHP, Sencha Touch & C++, SEO, Finance, Strategy & E-commerce. He speaks English and German and has worked in the US, Europe, and Asia. At Education Ecosystem he is the CEO and runs business operations.
Related posts
Career DevelopmentContent Creators

Meet Yuzby, An Inspiring Developer From Nigeria

Data Science

R Tutorial for Data Science Part 1

Content CreatorsCryptocurrency

Main Technical Differences between Tron, VET, NEO and Ethereum Blockchains

Coding Community

Google's Go Programming Language Is Going Places—By How Far?