achi achi - 3 months ago 6x
jQuery Question

jQuery autocomplete: How to obtain HTML item's "id" attribute?

jQuery is new to me, thanks for bearing with me.

I have some text inputs in HTML:

<input type="text" class="NameTextID" id="fn.1">
<input type="text" class="NameTextID" id="ln.1">
<input type="text" class="EmailAddressTextID" id="ea.1">

Two inputs are of class
and one is of class
. Notice each id is unique.

I then would like to leverage jQuery's autocomplete function on any DOM item with a class from above.

$(document).ready(function() {
$(function() {
$( ".NameTextID" ).autocomplete({
source: recEngineNames,
minLength: recMinCharCount,
select: recEngine
$( ".EmailAddressTextID" ).autocomplete({
source: recEngineEmails,
minLength: recMinCharCount,
select: recEngine,

Now, in the function recEngine:

var recEngine = function(event, ui) {
var selected_value = ui.item.value
var selected_id = ????

jQuery passes two parameters, how can I obtain the id if the ui item that activated the recEngine function?

Thanks in advance!


You can just do:-

var selected_id =;

where this refers to the current element being referred to.