jQuery selector for a checkbox that contains certain text in its name attribute

前端 未结 3 1791
庸人自扰
庸人自扰 2021-01-06 08:44

I\'m trying to find a selector in jQuery that select all inputs that are checkboxes and their name contains a specific word like \"top\" or \"Top\". Having trouble b/c its

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-06 09:21

    I believe you could combine the :checkbox selector and the attribute-contains selector:

    $("input:checkbox[name*='top']").each(); 
    

    Not sure if it needs to be case insensitive, in that case you could have a look at this SO question.

    Update:

    As bažmegakapa points out in his comment, :checkbox selector is deprecated according to the documentation. Therefor it is probably better to use:

    $("input[type=checkbox][name*='top']").each();
    

提交回复
热议问题