I have several input fields that are enhanced with jQuery auto-complete functionality. How to get the corresponding input field when a select event is triggered?
<input name="1" value="">
<input name="2" value="">
<input name="3" value="">
$('input[type=text]').autocomplete({
source: 'suggestions.php',
select: function(event, ui) {
// here I need the input element that have triggered the event
}
});
I was using an anonymous function for the
source
param, and$(this)
inside it referenced the funcion, not the element that was triggering it. I had to use$(this.element)
.The final code ended similar to this (I simplified it for demo purposes):
You can use
$(this)
orevent.target
.Then you can get the name using
$(this).prop('name')
orevent.target.name
.demo
Try using
$(this)
As far as I can tell for this example, you wouldn't need the
$()
.this
would work just fine since name is a defined attribute.this.name
Use
$(this)