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

前端 未结 3 1766
庸人自扰
庸人自扰 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:01

    You were close...

    $("input[type='checkbox'][name^='Top']").each()
    

    jsFiddle Demo

    0 讨论(0)
  • 2021-01-06 09:14

    you can use start with selector:

    $("input[name^='Top']")
    

    or:

    $("input[name^='Top']:checkbox")
    
    0 讨论(0)
  • 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();
    
    0 讨论(0)
提交回复
热议问题