2

i have a lot of input fields like:

<input type="hidden" value="" name="participants[1][canceled]">
<input type="hidden" value="" name="participants[2][canceled]">
<input type="hidden" value="" name="participants[3][canceled]">

I am looking for a jQuery selector that gives me all of these items. I dont want to use a loop. I would prefer something like:

jQuery('[name="participants[*][canceled]"]') // actually dont work

Is that possible?

Thank you

EDIT: Thanks to all of you

$(':hidden[name^="participants["][name$="][canceled]"]');

Was my solution and works like a charm. Ty

d-bro82
  • 490
  • 1
  • 6
  • 21

6 Answers6

2

Try to use the attribute starts with selector in your context,

jQuery('[name^="participants"]')
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
2

To be precise this is the correct way:

$(':hidden[name^="participants["][name$="][canceled]"]');

Or if you need to match numbers only:

$(':hidden').filter(function() {
    return /^participants\[\d+\]\[canceled\]$/.test(this.name);
});

DEMO: http://jsfiddle.net/qbgAL/

VisioN
  • 143,310
  • 32
  • 282
  • 281
1

If you just want the array name then you can just use participants

Live Demo

jQuery('[name*=participants]')
Adil
  • 146,340
  • 25
  • 209
  • 204
0

I would use something like $("input:hidden[name^='participants']")

JudgeProphet
  • 1,687
  • 3
  • 26
  • 44
0

Try this :Refrence

$('[name ="participants"][name $="[canceled]"]')
Community
  • 1
  • 1
Ankit Tyagi
  • 2,381
  • 10
  • 19
0

Try this:

jQuery('[name^="participants"][name$="[canceled]"]')
Jai
  • 74,255
  • 12
  • 74
  • 103