Three methods for jQuery to determine whether the checkbox is selected

web front end six thousand two hundred and fifty-three 7 years ago (2017-02-16)

The check box selection status of forms is often judged in projects, and the following three common methods are summarized:


Method 1 (recommended):

 if($("#checkbox").is(":checked")) {     // do something }

Method 2:

 if ($("#checkbox").attr("checked")) {     // do something }

Method 3:

 if ($("#checkbox").get(0).checked) {     // do something }