Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select an element with its name attribute in jQuery? [duplicate]

How to get an element with its name attribute with jQuery?

Is there anything (like # for id and . for class) for name in jQuery?

like image 246
MSajjadi Avatar asked Mar 13 '12 07:03

MSajjadi


People also ask

How do you select an element with the same name?

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.

How do you find the value of an element with a name instead of ID?

Just type the name of the element without "<" and ">" characters. For example type P, not <P> if the answer is the <P> element.

How do I select a specific Dropdownlist using jQuery?

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”).


2 Answers

$('[name="ElementNameHere"]').doStuff(); 

jQuery supports CSS3 style selectors, plus some more.

See more

  • jQuery - Selectors
  • jQuery - [attribute=""] selector
like image 91
Madara's Ghost Avatar answered Oct 08 '22 01:10

Madara's Ghost


You 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 
like image 44
steveukx Avatar answered Oct 08 '22 00:10

steveukx