In the following code, .live() don’t work, but .autocomplete() does. Why? (See http://jsfiddle.net/fRpCy/1/)
var input = [];
input.push($('input'));
$(input).live('keydown', function (event) {
console.log('You have pressed a key!');
});
$(input).autocomplete({ source: ['test1', 'test2'] });
The
.live()query-object method operates on queries that are fundamentally selectors.$([$('input')])is not a selector query, it’s a query over an array containing a selector query.From the docs:
Copied from my comment below:
.autocomplete()works because it operates more in line with other jQuery functions, which enumerate the objects provided by the query and act on them immediately..live()does not enumerate, but rather inspects the query at a later time — whenever any event is fired. Since the query is not in the form it is expecting, it simply ignores it.