jquery Notes-Basic knowledge

Source: Internet
Author: User

jquery is a JavaScript library that gets a complete set of defined methods by encapsulating native JavaScript functions. In a jquery program, both the selection of page elements and the built-in function functions are the starting point of the dollar sign "$". And this "$" is the most important and exclusive object of jquery: jquery object. In itself is the abbreviated form of the jquery object:

$ (function// execute an anonymous function equivalent to jquery (function () {});

And the JQuery method returns the JQuery object, so you can use the Concatenating method:

// concatenating

and "#box" is the way to select elements based on the ID

Notes

Code annotations and JavaScript are consistent in jquery, with two of the most common comments: single-line use of "/...", multiline use "/* ... * *"

Load Code mode

In JavaScript, we wait for the page body to wait for loading using the window.onload (function () {}) method, while jquery uses $ (document). Ready (function () {}) The shorthand method is $ (function () {});

get native DOM elements

In JavaScript we are using:

// get the DOM element of Id=box

In jquery you can use, after all, the encapsulation of JavaScript, the original thing can not be used too much to say, but jquery want to reach the original DOM object could be like this:

Alert ($ (' #box '). Get (0));

dealing with conflicts between jquery and other libraries

For example, if you have a library that uses "$", it will conflict with jquery. Outcome measures:

1. You can put this library behind the jquery Library, "$" belongs to this library, and jquery can use jquery objects instead of "$", or create a new character for JQuery to use:

var // Create a $$ jquery object $ (function  () {alert ($$ (/// This is JQuery's $$});

2. If you feel that the sequencing of the processing library references is cumbersome, you can use Jquery.noconflict () and create a new character to combine the methods used by JQuery:

// Remove the $ character ownership var $$ = jquery;$ (function  () {alert ($$ (' #box '). width ());});

jquery Notes-Basic knowledge

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.