Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114447

Get form elements by name?

I would like to style all of the radio buttons with the same name in a form easily in a nice Prototype or jQuery-style shortcut.

$('billship').select('name:shipType') or something like that.

Does such a shortcut for form field names exist?

Upvotes: 14

Views: 20552

Answers (1)

Paolo Bergantino
Paolo Bergantino

Reputation: 488744

With jQuery:

$('#billship input:radio[name="shipType"]');  
$('input:radio[name="shipType"]', '#billship');

Both are equivalent, but the 2nd one performs slightly better and I personally prefer it.

With Prototype, I believe it would look like this:

$$('#billship input[type="radio"][name="shipType"]');

Upvotes: 30

Related Questions