How do I check whether a checkbox is checked in jQuery?

前端 未结 30 3532
花落未央
花落未央 2020-11-21 04:44

I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery.

For example, if the age checkbox is

30条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 05:01

    There are many ways to check if a checkbox is checked or not:

    Way to check using jQuery

    if (elem.checked)
    if ($(elem).prop("checked"))
    if ($(elem).is(":checked"))
    if ($(elem).attr('checked'))
    

    Check example or also document:

    • http://api.jquery.com/attr/

    • http://api.jquery.com/prop/

提交回复
热议问题