0

I've got some autocomplete:

 $(".some_class").autocomplete({ source: function(request,response){ //get input values and store into myArray var element= $(this); //not working 

.some_class is connected to input fields, which is what I actually want to have. I thought $(this) would return the the input field. Instead I'm getting this:

Object { element={...}, options={...}, menu={...}, mehr...}

How can I access the element? When I used it like that before, I had no problems accessing the element.

EDIT:

Actually I want the value of the name-attribute of the input-field. Do you have an Idea how to manage that?

2
  • Could you just write <code>var element=$(this).element;</code>? Commented May 20, 2014 at 13:55
  • $(this) is the jquery wrapper object. You can use array indexers to access the DOM object. Try $(this)[0]. However, you may have a different problem depending on what the value of this is in your context. Commented May 20, 2014 at 13:56

1 Answer 1

2

I believe you're looking for:

var element = this.element; 

element is already a jQuery object.

Here is the demo I used for testing: http://jsfiddle.net/y7vT4/

Sign up to request clarification or add additional context in comments.

4 Comments

That's it. But I never needed the element part yet when I wanted to access the element. Why do I need it here?
It's just the way the source method was built. I don't think they thought the element should be this in this case. In a method like change, this is the element.
api.jqueryui.com/autocomplete/#option-source - It seems the "options" from the api get the "options" as this and "events" get the element as this. I'm sure they have good reasons for it haha.
The reason is simple: The data object has several useful values, other than the element, like "isMultiLine", "term", "option", etc...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.