You are making wrong assumptions about .closest()
and how .text()
works. Please make a habit of studying the documentation when in doubt, it gives clear descriptions and examples on how to use jQuery's features.
.closest()
will traverse the parents of the given element, trying to match the selector you have provided it. If your.select_link
is not "inside".address
, your code will not work.Also,
.text()
is a method, not a property (in the semantical way, because methods are in fact properties in Javascript).x.text = 1;
simply overrides the method on this element, which is not a good idea, you want to invoke the method:x.text(1);
.
Something along these lines might work:
var t = $(this).closest('tr').find('.address').text();
$('#booking_address').text(t);
If #booking_address
is a form element, use .val()
on it instead.
If it does not work, please provide the HTML structure you are using (edit your question, use jsFiddle or a similar service) and I will help you. When asking questions like this, it is a good habit anyways to provide the relevant HTML structure.