jQuery - How to select all checkboxes EXCEPT a specific one?

前端 未结 4 2085
余生分开走
余生分开走 2021-01-05 12:42

I have a jQuery selector that looks like this ...

$(\"input:checkbox\").click(function(event) {
  // DO STUFF HERE
}

Everything was working

4条回答
  •  我在风中等你
    2021-01-05 12:52

    Well.. we need to know more about the HTML for a specific answer, but there are two methods that I can think of.

    1) if you know the name of the one that you don't want then remove that one with not

    $("input:checkbox").not('#the_new_checkbox_id').click(function(event) {
      // DO STUFF HERE
    }
    

    2) use something that the correct inputs have in common to select them.

    $("input:checkbox[name=whatItIsNamed]").click(function(event) {
      // DO STUFF HERE
    }
    

提交回复
热议问题