I know that $(this) results in a jQuery object, but i often see (especieally in jQuery plugins) the use of return this.whatever what is the general rule?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on what
thisrefers to.Inside an event handler function
thisrefers to the HTML element the event is raised from. To perform jQuery operations on the element, you use$(this)to wrap the HTML element.thisin the scope of a plugin method refers to the jQuery selection object itself. Additionally, in plugins the jQuery methodeachis used to perform a function to each element in a jQuery selection. This is often the way plugins are written to provide a new method:In short, it’s all about the context of the method. The jQuery documentation explains this concept whenever you’re looking at methods which change the value of
this.