Here an example
$newattribute.children("div").children("input,select").each(function (i) {
var $currentElem = $(this);
$currentElem.attr("name", $currentElem.attr("name") + current);
$currentElem.attr("id", $currentElem.attr("id") + current);
});
HTML
<div>
<table class="table">
<tr>
<td><select id="attribute_name" name="attribute_name">
<option value="1">Size</option>
<option value="2">Color</option>
</select></td>
<td><input type="text" id="attribute_value" name="attribute_value"></td>
<td><input type="text" id="attribute_qty" name="attribute_qty"></td>
<td><input type="text" id="attribute_price" name="attribute_price"></td>
</tr>
</table>
</div>
How do I use .children("div") correctly to find name & id?
Don’t use
.children()because it finds, well, children. As in, not grandchildren, not great-grandchildren, just immediate children. To find descendants use.find(). So:You don’t say what
$newattributeis, but assuming it is the immediate parent of the div element shown in the question then the statement I just showed will find all input and select elements that are descendants of that div.The API doco for
.children()explains this further, and links to the doco for.find().