user1572796 user1572796 - 1 year ago 71
jQuery Question

jQuery autocomplete on class, how to get id

I have been working on this a while and can't seem to get anywhere. Basically I have the autocomplete on a bunch of inputs by class, but I need to get the specific inputs id to build the object to post the ajax (I have to use POST for this project not GET).

source: function( request, response ) {
// here is where I get the hash from local storage,
// reference the id and build the object
// tried, $(this).prop('id'), no luck
url: '/somepath/filename.htm',
contentType: 'application/json',
dataType: 'json',
type: 'POST',
data: JSON.stringify(obj),
success: function(json) {
return {
label: item.label,
value: item.label
error: function() {
// error handling
}); // ajax
} // source

Answer Source





Inside of the source callback, this refers to the widget instance. In order to get the element the widget is attached to, you should use this.element, which is a jQuery object.