user2219071
user2219071

Reputation: 113

How to use JQuery selector for select input name and input name in array?

can you help me. I need select with JQuery input with name and input with name in array.

<input type="text" name="name">
<input type="text" name="shippingAddress[name]">

I try this, but this not work.

var name = $('[name^="name"]');

Upvotes: 2

Views: 188

Answers (3)

Eli
Eli

Reputation: 14827

To select input with name:

$('input[name=name]')

To select input with name as array field:

$('input[name="' + shippingAddress + '[]"]')   

Upvotes: 0

bipen
bipen

Reputation: 36551

try attribute selector

var name = $('[name^="shippingAddress\\[name\\]]');

Upvotes: 0

Anthony Grist
Anthony Grist

Reputation: 38345

You could use the attribute-contains selector:

var name = $('[name*="name"]');

That will select any element where its name attributes value contains the substring "name", so will match both <input type="text" name="name"/> and <input type="text" name="shippingAddress[name]"/>.

Upvotes: 1

Related Questions