Steven
Steven

Reputation: 19455

Why am I not able to get the data() value of my autocomplete input field?

I'm using jQuery autocomplete on the following input

<input data-searchurl="Some url" />

But when I try to retrieve the data value searchurl, I get undefined.
Hmm... I get the same if I try using attr as well.

$('input').autocomplete({
    source: function (request) {
        var url = $(this).data('searchurl');
        (...)

See my fiddle here: http://jsfiddle.net/34ewgg7j/3/

Why is autocomplete preventing me from doing this?

Upvotes: 0

Views: 73

Answers (1)

Basster
Basster

Reputation: 310

use $(this.element).data('searchurl') and it works, that will point to each individual input in the collection, if you have multiple inputs in the selector.

Upvotes: 2

Related Questions