jquery Learning Notes 7 Methods of jquery construction function _jquery

Source: Internet
Author: User
Tags event listener

One: $ (selectorstr[, restricted Range]), accepts a selector (a string that conforms to the jquery specification), returns a JQuery object;

Copy Code code as follows:

$ (selector[, restricted range])
$ (". Guo"). Click (function () {//There is no context parameter here
$ ("A.aguo", this). css ({"Color": "Red"});//this is the context parameter for scoping
});

Two: $ (htmlstr[, Document Object]), $ (Html[,json object]) passing in an HTML string, creating a new DOM element

When a string is passed in, the constructor determines whether it is a selector string or an HTML string.
If it is a selector string: Then traverse the DOM to find the element that matches it, and if there is no matching element,
Returns an empty jquery object, or it will create a pair of jquery objects from these matching elements.

Copy Code code as follows:

$ (htmlstr[, Document Object])
$ ("<div> everyone Good </div>"). Append ("body"); Simple tags: no tape nodes

Three: $ (DOM Element), $ (DOM element collection) converts DOM elements into jquery objects.

The jquery constructor creates a DOM node using the original Eco-method of JS Document.createelement ()

Copy Code code as follows:

$ ("<div><a> everyone Good </a></div>"). Append ("body"); Complex tags: contains child nodes.

Four: $ (custom object) encapsulates a generic object as a jquery object.

jquery uses the document fragment Buildfragment () method to insert all child nodes into [, document objects] all at once, if not specified here, is document; $ (Html[,json object])

When HTML is a simple label, her second argument can be a JSON object that contains the properties or events of the DOM element.

Copy Code code as follows:

$ (Html[,json object])
$ ("<div></div>", {
"Class": "Gys",//Because class is the keyword of JS, so quote
Text: "Everyone is good",
Click:function () {alert ("What am I Doing");}
}). Append ("body");

The $ (callback function) binds the Ready event listener to execute when the DOM load completes.

$ (Element) or $ (elements)

Pass in a DOM object or a set of Dom objects

Copy Code code as follows:

("Div.guo"). Click (function () {
$ (this). Slideup ();
});

VI: $ (jquery object) accept a jquery object that returns a copy of a jquery object

$ (object);

Pass in a normal object

Copy Code code as follows:

var obj = {name: "Guo", age:24};
var $obj = $ (obj);
$obj. On ("Guo", function () {
Alert ("Departs from a custom event");
});
$obj. Trigger ("Guo");

Seven: $ () Create an empty jquery object.

$ (callback) pass in a function

Copy Code code as follows:

$ (function () {})

This representation executes in the function after the DOM has finished loading.

$ (jQuery Object);

Passing in a jquery object, a copy of the jquery object is created and returned, and the replica references the same DOM object as the Passed-in jquery object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.