jquery - Accessing various child elements of a table -
i trying access elements on same <tr> level seen below
<tr> <td ><input type='text' value='{$result['name']}' name='itemname' /></td> <td><input type='text' value='{$result['quantity']}' name='itemquantity' /></td> <td><input type='text' value='{$result['cost']}' name='itemprice' /></td> <td><input type='submit' name='submit' value='submit'/></td> </tr> i want click on submit button , each value 3 input fields sent on post connection, far tried accessing these values doing
$(this).parent("tr").children("td input").val(); which results in undefined result.
parent selects parentnode element of selected element(if matches specified selector), can use closest method:
$('tr input[type=submit]').click(function(event) { event.preventdefault(); var data = $(this).closest('tr').find('input').serializearray(); // using "siblings" method // var data = $(this).parent('td').siblings().find('input').serializearray(); });
Comments
Post a Comment