JQuery Introduction 1

Source: Internet
Author: User

JQuery Constructor
Advantages of JQuery
Small volume (v1.2.3 15kb)
Rich DOM selectors (CSS1-3 + XPath) across browsers (IE6, FF, Safari, Opera)
Blockchain chain code
◦ Powerful event and style support
◦ Powerful AJAX Functions
Extensions are easy to expand and many plug-ins are available.
JQuery constructor receives four types of parameters:
1. jQuery (expression, context)
2. jQuery (html)
3. jQuery (elements)
4. jQuery (fn)
First, find the elements in the document based on the expression (ID, DOM element name, CSS expression, and XPath expression), and assemble them into a jQuery object to return.
DEMO:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> jQuery basic </title>
<Style type = "text/css">
. Selected
{
Background-color: Yellow;
}
</Style>
<Script src = "../scripts/jquery-1.2.3.intellisense.js" type = "text/javascript"> </script>
</Head>
<Body>
<H3> jQuery constructor <Ul>
<Li> jQuery (expression, context) </li>
<Li> jQuery (html) </li>
<Li> jQuery (elements) </li>
<Li> jQuery (fn) </li>
</Ul>
<Script type = "text/javascript">
</Script>
</Body>
</Html>
Add the following jQuery code to the script block at the end of the text:
JQuery ('ul> li: first '). addClass ("selected ");
JQuery () can be replaced with the shortcut $ (). If $ is occupied by other objects, you can use the jQuery. noConflict () function to cancel the shortcut.
In "ul> li: first", ul> li indicates all li elements under ul (CSS expressions, which can be ul/li in XPath mode). first indicates the first element. AddClass () is a function used by jQuery objects to add CSS style classes. The opposite function is removeClass ().
Add the following code:
$ ('Ul '). append ($ (' <li> new item </li> '));
$ ('<Li> new item </li>') converts the string to a DOM object, and adds it to the end of the ul object through the append () function.
Next:
$ (Document). ready (function (){
Watermarks ('ul').css ('color', 'red ');
});
The jQuery constructor can also pass in DOM objects, such as document or jQuery objects (of course it doesn't make any sense ). The ready () function adds an event handler for the document and sets the ul color to red.
$ (Document). ready () can be replaced directly with $ (fn) because of many application scenarios. fn indicates the processing function. (The ready processing function appears to be executed after the document content is loaded, and does not need to wait for other resources such as related images to be loaded, so it is executed earlier than the load event.
$ (Function (){
Alert ('Welcome to jQuery ');
});
The above code works as soon as the page is loaded, a dialog box is displayed.

Related Article

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.