Jquery Learning (3) selector and jquery learning Selector

Source: Internet
Author: User

Jquery Learning (3) selector and jquery learning Selector

1. The most important thing in Jquery is the selector.

Learning points:
1. Simple Selector
2. Advanced Selector
3. Advanced Selector


① Simple selector.

The simplest is the most commonly used, and the most commonly used is also the simplest.

When using the jQuery selector, we must first use the "$ ()" function to wrap our CSS rules. When the CSS rule is passed to the jQuery object as a parameter, the jQuery object containing the corresponding elements on the page is returned. Then, we can perform behavior operations on the obtained DOM node.


# Box {
// CSS rules using ID Selector
Color: red;
// Red the font color of the element whose ID is box
}


In the jQuery selector, we use the following method to obtain the same result:


(('{Box'}.css ('color', 'red ');
// Obtain the DOM Node object and add the behavior


 


Warning: The ID can only appear once on the page. Generally, developers are required to abide by and maintain this rule. However, if you appear three times on the page and use a style in CSS, the three elements will still be executed. However, if you want to do this in jQuery, you will encounter blindness. Therefore, developers must develop a good habit of observing and use only one ID on a page.


(('{Box'}.css ('color', 'red ');
// Only the first ID turns red, and the last two are blind.



② Advanced Selector

③ Advanced Selector

 



?? JQuery learning recommendations

1. First, you must be familiar with html and javascript.
2. Read "Learning jquery from scratch" (I don't quite remember the title of the book). After reading this book, I feel that the general usage is almost the same.
3. You still need to do more exercises. jquery's selector is very powerful.

Jquery selector Problems

<Td> <span> 3 </span> <a class = "add"> + </a> </td>

$ (Function (){
$ ('. Add'). click (function (){
Var o = $ (this). prev ();
Var val = o. text ();
O. text (val-1 );

});

});

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.