jQuery: Selecting by class and input type

前端 未结 6 1252
忘了有多久
忘了有多久 2021-01-30 05:51

I would like to select a set of elements that are both of a certain input type (say, a checkbox) and have a certain class using jQuery. However, when I try the following:

6条回答
  •  梦如初夏
    2021-01-30 06:42

    You have to use (for checkboxes) :checkbox and the .name attribute to select by class.

    For example:

    $("input.aclass:checkbox")
    

    The :checkbox selector:

    Matches all input elements of type checkbox. Using this psuedo-selector like $(':checkbox') is equivalent to $('*:checkbox') which is a slow selector. It's recommended to do $('input:checkbox').

    You should read jQuery documentation to know about selectors.

提交回复
热议问题