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?
In order to access the form element, we can use the method getElementById() like this: var name_element = document. getElementById('txt_name'); The getElementById() call returns the input element object with ID 'txt_name' .
The getElementsByName() method returns a collection of elements with a specified name. The getElementsByName() method returns a live NodeList.
The Form Object in HTML DOM is used to represent the HTML < form > element. This tag is used to set or get the properties of < form > element. This element can be accessed by using getElementById() method.
To get all <form> elements in the document, use the document. forms collection instead.
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"]');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With