Reputation: 113
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
Reputation: 14827
To select input with name:
$('input[name=name]')
To select input with name as array field:
$('input[name="' + shippingAddress + '[]"]')
Upvotes: 0
Reputation: 36551
try attribute selector
var name = $('[name^="shippingAddress\\[name\\]]');
Upvotes: 0
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