Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

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 selecting other checkboxes.

Is it possible to use something like:

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

Top 1<input type="checkbox" name="Top1" /><br />
Top 2<input type="checkbox" name="Top2" /><br />
Top 3<input type="checkbox" name="Top3" /><br />
Top 4<input type="checkbox" name="Top4" /><br />

Bottom 1<input type="checkbox" name="Bottom1" /><br />
Bottom 2<input type="checkbox" name="Bottom1" /><br />
Bottom 3<input type="checkbox" name="Bottom1" /><br />
Bottom 4<input type="checkbox" name="Bottom1" /><br />

I only want to select the check boxes which contian the word "top" in its name.

like image 768
RetroCoder Avatar asked Jul 05 '12 17:07

RetroCoder


2 Answers

You were close...

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

jsFiddle Demo

like image 114
Mark K Avatar answered Nov 15 '22 05:11

Mark K


you can use start with selector:

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

or:

$("input[name^='Top']:checkbox")
like image 41
undefined Avatar answered Nov 15 '22 07:11

undefined