jQuery's core functions


Compared to any web front-end development workers, for the jQuery framework is more than familiar, I opened the jquery development documentation a few days ago to see so many APIs, or part of the relatively unfamiliar, although most of the development time is used jQuery, for this reason I decided to still warm up to know the new, to review again the jQuery development documentation, look at the end or a lot of gains, at least for some of the fuzzy, know so write to achieve the purpose of the function, once again after reading understand a lot it! Without further ado, here are the personal review notes.

I. Core functions

1、jquery([selector,[context]])

Of which.

selector: the string to look for

context: as a set of DOM elements, document or jquery object with lookup

This is the most core function of the framework jquery, and almost all of the core functionality is implemented through this function; its basic usage is to pass it an expression (typically consisting of a CSS selector) and then find all matching elements based on that expression. Usually in the use of jquery development, rarely use the context parameter, his role is actually to specify the function from where to find the matching elements, do not write this parameter, $ () is in the current HTML document to find the DOM elements.

Let's go straight to the example.

2、jQuery(html,[ownerDocument]|[props])

Of which.

html: HTML tag string for dynamically creating DOM elements

ownerDocument: create the document where the DOM element is located

props:Properties, events and methods to attach to newly created elements

Understanding directly by example :

$("

",{

"class":"test",

text:"Click me!",

click:function(){

$(this).toggleClass("test");

}

}).appendTo("body");

3、jQuery(callback)

Shorthand for $(document).ready(), which allows you to bind a function that executes when the DOM document has finished loading. You can use as many $(document).ready events as you want in a page.

Example.

4、jQuery.holdReady(hold)

Pauses or resumes the execution of the .ready() event, but must be called before the execution of the .ready event, otherwise it has no effect; to delay the ready event, call $.holdReady(true), and while the ready event is executing, call $.holdReady(false);

Example.

II. Subject visits

1、each(callback)

Match each element to execute a function as a context; each time the function is passed in, this in the function will point to a different DOM element and will also be passed the index value where the currently executed element is located; return false to stop the loop, return true to move on to the next loop

Example.

html:

js:

2、size()

Get the number of elements in a jquery object

html:

js:

Results.

3、length()

Get the number of elements in a jquery object

html:

js:

Results.

4、selector

Returns what selector you used to find this element. Can be used with context for precise detection of selector queries. Development plug-ins commonly used

Example.

5、get([index])

Get one of the matching elements, $(this).get(0) is equivalent to $(this)[0]

Example.

html:

js:

Results.

6、index([selector|element])

Searches for matching elements and returns the index value of the corresponding element, counting from 0

Example.

html:

js:

III. Data Caching

1、data([key],[value])

Of which.

key:Name of the data stored

value:Any data to be stored

Store data (in any format) on the element, returning the jQuery object

Example.

html:

js:

2、removeDate([name|list])

Removal of stored data from an element

Example.

$("div").removeDate("greeting");

four Plug-in mechanism

Used to extend new methods (often used to make plugins)

Example.

2、jQuery.extend(object)

Extending the jQuery object itself

Example.

Results.


Recommended>>
1、Blockchain ushers in the 30 era without knowing this you will be kept out
2、treasure box for gathering treasures
3、The last piece of clean land for chicken is also going to disappear KAKAO servers will be locked IP domestic can not log in
4、What you should know about the evolution of Android network access methods
5、Dutch emergency artificial intelligence goes online to help operators determine medical conditions

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号