I am developing an Application in Asp.Net Core MVC6.
I have a Razor page that render dynamically object.
Assuming I have creating dynamically this two Divs
in my page
<div id="A1">
<input type="text" id="SearchSSN" />
<input type="text" id="SearchLastName" />
</div>
<div id="A2">
<input type="text" id="SearchSSN" />
<input type="text" id="SearchLastName" />
</div>
<a href="#" onclick="Search()" class="nav-link px-4 py-4" title="Show All"></a>
When I call Search()
function in javascript, I want to read the value inside each Div
function Search() {
-- to read value from Object
var SSN: $("#SearchSSN").val(),
}
But I want to read the value inside each Div
Something like
$("#A1").("#SearchSSN").val()
$("#A2").("#SearchSSN").val()
How can I Do it?
Thanks
2
Answers
Modify your
Search()
Method like thisYou can find all your divs using
querySelectorAll
and then usemap
to pull the values out into an array usingquerySelector
to find the input inside the div.Here is an example that will just log the values to the console when you click ‘Search’