How can I detect whether or not an input box is currently a jQuery UI autocomplete? There doesn't seem to be a native method for this, but I'm hoping there is something simple like this:

if ($("#q").autocomplete)
  //Do something

That conditional, however, seems to always return true.


It's true because once you've included the autocomplete js, every $() object now has a autocomplete() method defined (in case you want to activate autocomplete for those elements). Your if() is just saying that that function is not null.

I, unfortunately don't have a system where I can check this (left the laptop home today), but I believe autocomplete adds a css class name to the elements it's using. You could look for that.

James Curran
+5  A: 
if ($("#q").hasClass("ac_input")) {
    // do something
+1  A: 

You can use

if( $.isFunction( $.fn.autocomplete ) ){ }

.isFunction is part of the jQuery lib. (cite: