Reputation: 2284
I have a set of buttons that, when clicked, should select the first text box after the button and insert the date. My issue is that since my form is dynamically generated, hard coded transversing won't work (i.e. the text box isn't always immediately after the button, there may be other elements inbetween). I have tried using find()
, but that doesn't seem to be working. Any ideas?
$('.required').on('click',function(){
...
$(this).find(".timestamp").first().val(dateStr);
...
});
EDIT:
$(this).parent().parent().siblings().find(".timestamp").first().val(dateStr);
A bit closer, but the above always populates the value for the first textbox on the page. I've tried using closest() instead of first(), but that doesn't seem to work either. Any ideas?
Upvotes: 0
Views: 95
Reputation: 8444
.find()
traverses the elements descendants, not the element's siblings.
It sounds like you want something more like:
$(this).siblings('.timestamp').first().val(dateStr);
Upvotes: 1