Home > Web Front-end > JS Tutorial > Usage analysis of jQuery() method in jQuery_jquery

Usage analysis of jQuery() method in jQuery_jquery

WBOY
Release: 2016-05-16 16:24:12
Original
1390 people have browsed it

The examples in this article describe the usage of the jQuery() method in jQuery. Share it with everyone for your reference. The details are as follows:

Definition and usage of jQuery() method:
This method can accept a set of selectors to match the corresponding elements. For example:

Copy code The code is as follows:
jQuery("div")

In practical applications, $ is generally used to define jQuery. In fact, $ is the abbreviation of jQuery. For example, $("li") can be written as jQuery("li").
The core functions of jQuery are all implemented through this method, or are implemented using this method in some way. The following is a detailed introduction to the usage of this method.
Grammar structure 1:
When the jQuery() method does not have any parameters, it will return an empty jQuery object.

Copy code The code is as follows:
jQuery()

Example code:

Copy code The code is as follows:






jQuery() function-Script Home







Grammar structure 2:

Copy code The code is as follows:
jQuery(selector,context)

Parameter list:

参数 描述
selector 用来匹配元素的选择器。
context 可选。待查找的DOM元素集、文档或者jQuery对象。
如果没有指定,则就是当前整个文档。

If not specified, it is the entire current document.

Example code:
Example 1:

Copy code The code is as follows:






jquery() function-Script Home






  • DIV CSS Zone

  • jQuery Zone

  • HTML Zone




  • ASP Zone

  • Script HouseWelcome


The sun is out





The above code can set the font color in the li element to red.
Example 2:

Copy code The code is as follows:






jquery() function-Script Home






  • DIV CSS Zone

  • jQuery Zone

  • HTML Zone




  • ASP Zone

  • Script HouseWelcome


The sun is out





The above code sets the font color in the li element in the div to red.
Grammar structure three:
Convert DOM elements and DOM element arrays into jQuery objects.

Copy code The code is as follows:
jQuery(element|elementArray)

Parameter list:

参数 描述
element 要转换成jQuery对象的DOM元素。
elementArray 要转换成jQuery对象的DOM元素数组。

Example code:
Example 1:

Copy code The code is as follows:






jquery() function-Script Home






  • DIV CSS area

  • jQuery Zone

  • HTML Zone




  • ASP Zone

  • Script HouseWelcome


The sun is out





The above code can set the font color in the li element with id first to red.
Example 2:

Copy code The code is as follows:






jQuery() function-Script Home






  • DIV CSS area

  • jQuery Zone

  • HTML Zone




  • ASP Zone

  • Script HouseWelcome


The sun is out





Grammar structure four:

Copy code The code is as follows:
jQuery(callback)

jQuery (callback) is the abbreviation of $(document).ready(), which is used in several examples above.
Its function is to execute the callback function
after the document is loaded. Parameter list:
参数 描述
callback 文档加载完成之后要执行的函数。

Example code:

Copy code The code is as follows:






jQuery() function-Script Home






Copy code The code is as follows:
jQuery(function(){
alert("Document loading completed");
})

The function is the same as the following code:

Copy code The code is as follows:
$(document).ready(function(){
alert("Document loading completed");
})

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template