Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all elements with same name inside some specific div using jQuery [duplicate]

We have two divs: How to select all the input field as an array with name="divText" that are inside "div2".

//Body of div1

<div id="div1>
<input type="text" name="divText" value="v1" />
<input type="text" name="divText" value="v2"/>
<input type="text" name="divText" value="v3"/>
</div>

//Body of div2

<div id="div2>
<input type="text" name="divText" value="q1" />
<input type="text" name="divText" value="q2"/>
<input type="text" name="divText" value="q3"/>
</div>
like image 338
bpbhat77 Avatar asked Jan 31 '14 11:01

bpbhat77


People also ask

How do I select all elements with the same ID?

Here is a solution: You can use JQuery selector $("[id='idofelement']") to select all the elements with matching ID.

How can I select an element by name with jQuery?

Answer: Use the Attribute Selector You can use the CSS attribute selectors to select an HTML element by name using jQuery. The attribute selectors provide a very flexible and powerful mechanism for selecting elements.

Which is the correct jQuery selector statement to select all div elements?

13. Which is the correct jQuery selector statement to select all <div> elements? Explanation: The statement $("div") is the correct syntax to select all <div> elements.

How do I select all elements in a div?

getElementsByTagName() that will select all the instances of a certain HTML element on the current webpage based on its tag name, i.e. <div> . Calling document. getElementsByTagName("div") is all you need to do to select all <div> elements on the current page using JavaScript.


1 Answers

Use Attribute Equals Selector [name="value"] along with ID Selector (“#id”). There is error in your html the closing quote of div id div1 and div2 is missing as well.

Live Demo

$('#div2 input[name="divText"]')
like image 119
Adil Avatar answered Sep 24 '22 09:09

Adil