How to get an element with its name
attribute with jQuery?
Is there anything (like #
for id and .
for class) for name in jQuery?
You can use the Attribute Equals Selector ( [name='value'] ) to select elements with the given name in jQuery. Note, this might return more than one element since one can apply the same name to multiple elements within the document.
Just type the name of the element without "<" and ">" characters. For example type P, not <P> if the answer is the <P> element.
Syntax of jQuery Select Option$(“selector option: selected”); The jQuery select option is used to display selected content in the option tag. text syntax is below: var variableValue = $(“selector option: selected”).
$('[name="ElementNameHere"]').doStuff();
jQuery supports CSS3 style selectors, plus some more.
[attribute=""]
selectorYou can use:
jQuery('[name="' + nameAttributeValue + '"]');
this will be an inefficient way to select elements though, so it would be best to also use the tag name or restrict the search to a specific element:
jQuery('div[name="' + nameAttributeValue + '"]'); // with tag name jQuery('div[name="' + nameAttributeValue + '"]', document.getElementById('searcharea')); // with a search base
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