I have a table with multiple rows, and each row contains three cells. Each cell contains a textbox, so it looks like this:
XXXX XXXX XXXX
on the keyup event of the first textbox, I want its contents to be copied into the second textbox, but not the third textbox.
my keyup event I can get a reference to the first textbox. Doing .parent() will give me the cell, and if I want, doing .parent() again will give me the row.
What JQuery can I use to get the adjacent textbox?
$('#mytable tr'). each(function() { var customerId = $(this). find("td:first"). html(); });
jQuery(". dname"). find("tr td:eq(1)"). val();
You can use .next()
to get the next sibling, like this:
var nextTD = $(this).closest("td").next();
//for your case:
$(this).closest("td").next().find("input").val($(this).val());
.parent()
works too, .closest()
is just a bit more flexible, for you could change your markup and it'd still go to the nearest <td>
parent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With