Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is this.element in a jquery function?

Tags:

jquery

I was reading an excellent explanation of the jQuery UI combobox by Jörn Zaefferer (here's the link).

The fourth line of code reads var select = this.element.hide()

Jörn says:

The var select references the select element on which the combobox gets applied. To replace the select with the text input, the select is hidden.

I am learning jQuery now, and I don't recall seeing this.element before. How is it different that just this?

like image 334
esther h Avatar asked Jan 31 '12 07:01

esther h


2 Answers

Inside a widget, "this" refers to the widget object itself, which contains a property "element". That "element" points to html element for which that widget has been applied.

like image 147
Dima Koderov Avatar answered Nov 18 '22 04:11

Dima Koderov


You can think of it like this.

this.element // is just normal jquery object

// for example
var element = $('.current-selected-dropdown');

// and then put this together inside ui object
this.element = element

I'm not sure if this would help you.

var Dropdown = {
    element: null,
    _init: function() {

        // here is the same this.element that you referred to. 
        this.element = $('.dropdown');
    }
}
like image 21
Rezigned Avatar answered Nov 18 '22 04:11

Rezigned