NimChimpsky
NimChimpsky

Reputation: 47290

How do I reference the sepcific object/dom element that an jquery-ui autocomplete function belongs to, when it has been applied to all inputs

$("input[type=text]").autocomplete({
minLength: 3,
source: function (request, response) {
        alert( $(this).val() );

I have 3 different input text box's, but $(this).attr("id") or this.id both returned undefined

Upvotes: 0

Views: 50

Answers (2)

NimChimpsky
NimChimpsky

Reputation: 47290

alert( $(this.element).attr("id") );

works.

Upvotes: 0

charlietfl
charlietfl

Reputation: 171669

Not sure what is available inside source regarding this. You can always log it to console to see what is returned. The following pattern is helpful for implementing plugins on many elements

$("input[type=text]").each(function() {
    var id = this.id;
    $(this).autocomplete({
        minLength: 3,
        source: function(request, response) {
            alert(id);
        }
    });
});

Upvotes: 1

Related Questions