I am unable to append image src using the closest img tag.
When autocomplete option select i want to populate the image for that row
HTML :
<td>
<div>
<img class="participantphoto" src="images/author2.jpg" width="50" />
<input placeholder="Type a letter to search students" class="form-control searchStudent formbottom" name="student[0][name]" type="text" autocomplete="off">
</div>
</td>
JS :
$(document).on("focus keyup", "input.searchStudent", function (event) {
$(this).autocomplete({
source: 'gdcontroller.php?action=search',
select: function (event, ui) {
console.log(ui);
event.preventDefault();
this.value = ui.item.label;
// line below fails
$(this).parent().closest( ".participantphoto" ).attr("src",ui.item.profile_pic);
},
focus: function (event, ui) {
event.preventDefault();
this.value = ui.item.label;
}
});
});
closest
doesn't do what you seem to think it does. – T.J. Crowder Dec 2 '16 at 17:22