Net-informations.com

How to Check a jQuery Checkbox is Checked or Not?

jQuery Checkbox

You can use the jQuery prop() method to check or uncheck a checkbox dynamically such as on click of button or an hyperlink etc.

To check the current state of the checkbox you must instead use the checked property . It is dynamically updated as the user checks/unchecks.

The above code returns true if checked, false if unchecked.

run this source code Try it Yourself

Full Source

jQuery prop() Method

jQuery prop() method returns properties and values of the selected elements. When prop() method is used to return the property value, it returns the value of the first matched element . This method returns undefined for the value of a property that has not been set, or if the matched set has no elements.

Syntax

example

The above code returns true if checked, false if unchecked.

run this source code Try it Yourself

Full Source

jQuery prop() Vs. attr()

The difference between prop() and attr() methods can be important in specific situations. Before jQuery 1.6 , the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behaviour. As of jQuery 1.6 , the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.

jQuery is() method

jQuery is() method is to check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments. If no element fits, or the selector is not valid, then the response will be 'false'. This method traverses along the DOM elements to find a match, which satisfies the passed parameter.

Syntax

example

The above code returns true if checked, false if unchecked.

run this source code Try it Yourself

Full Source










net-informations.com (C) 2019    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About