d-bro82
d-bro82

Reputation: 500

jQuery - select all inputs with array name

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

Upvotes: 2

Views: 1402

Answers (6)

Jai
Jai

Reputation: 74738

Try this:

jQuery('[name^="participants"][name$="[canceled]"]')

Upvotes: 0

Ankit Tyagi
Ankit Tyagi

Reputation: 2375

Try this :Refrence

$('[name ="participants"][name $="[canceled]"]')

Upvotes: 0

JudgeProphet
JudgeProphet

Reputation: 1729

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

Upvotes: 0

VisioN
VisioN

Reputation: 145388

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/

Upvotes: 2

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

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

jQuery('[name^="participants"]')

Upvotes: 2

Adil
Adil

Reputation: 148110

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

Live Demo

jQuery('[name*=participants]')

Upvotes: 1

Related Questions