This in jquery means "current object". This represents the current element in html. Use the "$(this)" statement to turn the html element into a jquery object, and then use the jquery method to process the current Object, the syntax is "$(this).jquery method name();".
The operating environment of this tutorial: windows10 system, jquery3.6.0 version, Dell G3 computer.
What does this mean in jquery
this is the dom object. To put it bluntly, it is the tags in html. $(this) is the dom object. The object is changed to a JQuery object, so that the Dom object can be processed using JQuery methods later.
First, let’s take a look at the $() symbol in JQuery. In fact, this symbol is equivalent to JQuery() in JQuery, that is, $(this)=jquery(); that is, this can return a jquery object. Then, when you alert($('#id')); on the web page, an [object Object] will pop up. This object object is also a jquery object.
The example is as follows:
<html> <head> <meta charset="utf-8"> <title>123</title> <script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p").click(function(){ $(this).hide();//$(this)是在方法click内,此处的$(this)表示的是当前调用click方法的对象$("p"),就是表示当前对象,当前调用该方法的对象 }); }); </script> </head> <body> <p>如果您点击我,我会消失。</p> <p>点击我,我会消失。</p> <p>也要点击我哦。</p> </body> </html>
Output result:
##Related video tutorial recommendation:The above is the detailed content of What does this mean in jquery. For more information, please follow other related articles on the PHP Chinese website!