jQuery - dynamic variables?
- by user331884
Newbie question. Given the following html.
<div id="mycontainer1" class="container">
<input type="text" class="name"/>
<input type="text" class="age"/>
</div>
<div id="mycontainer2" class="container">
<input type="text" class="name"/>
<input type="text" class="age"/>
<input type="text" class="address"/>
</div>
I'm trying to create a function where I can pass an element id and an array that contains the classes of the input values I want to get.
So for example,
var inputClasses = ['name','age'];
getInputValue('#myContainer1', inputClasses);
function getInputValue(elem, arr) {
var temp = {};
$(elem).each(function() {
// need a way to map items in array to variables
// but how do I do this dynamically?
var nameValue = $(this).find('.name').val();
var ageValue = $(this).find('.age').val();
});