The second day of JQuery learning by cainiao-it's not easy for students

Source: Internet
Author: User

Yesterday I spoke to you about some common JQUERY usage, which is the simplest.

Continue writing JQUERY objects today

Method for converting a Dom object to a JQuery object, $ (dom object );

Convert a Jquery object to a Dom object:

Var domobj = jqobj [0]

Var domobj = jqobj. get (0)

After converting to a DOM object, you can use the JS method ---- Haha, other usage, I believe, you know.

JQUERY operation style sheet [CSS]

View sourceprint? <Script type = "text/javascript">

$ (Function (){

$ ("# Mydiv" ).css ("background", "red ");

// Modify the CSS style sheet
View sourceprint? // $ ("# Mydiv") The following describes the selector. Now you know that this is an element that obtains the following ID = "mydiv,
View sourceprint? // Equivalent to: document. getElementById ("mydiv ");
View sourceprint? });

</Script>
View sourceprint? <Body>
View sourceprint? <Div id = "mydiv"> This is the location of the file used for testing </div>
View sourceprint? </Body> <BR>

 

To obtain a CSS style sheet, follow these steps:

$ ("# Mydiv" ).css ("background ");

Modify Value: $ ("# mydiv"). val ("test file ");

Get Value: $ ("# mydiv"). val ();

JQuery rarely uses attributes, because it is difficult to write attributes in a chain ". [Coming soon after chained programming]

JQuery Selector

 

First, write a simple HTML page.

Haha

Just put a few Divs.

View sourceprint? 1 View sourceprint? 01

02 <title> </title>

03

04 <script src = "jquery-1.5.1.min.js" type = "text/javascript"> </script>

05

06 <style type = "text/css">

07. divs

08 {

09 background-color: Red;

10}

11 </style>

12 <script type = "text/javascript">

13

14 // equivalent to the Loading Method

15 $ (function (){

16 $ (". divs"). click (function () {// locate all elements in the webpage

17 alert ($ (this). text (); // The text is displayed. this is only the element.

18 });

19 });

20 </script>

21

22

23 <body>

24 <div class = "divs">

25 111111

26 </div>

27 <div class = "divs">

28 222222

29 </div>

30 <div class = "divs">

31 33333

32 </div>

33 </body>

34

This method is the JQUERY selector.

How to Use the css style sheet selector $ (". className") is the css name.

The preceding method can be called if the following html Tag contains class = className;

Of course, you can use $ ("# idName") or $ ("tag name: body ")

Multi-condition selector:
$ ("P, div, span") and select p tag, div tag, and span tag element (similar to CSS selector)
Of course, you can select your Selector Based on your own needs. Be sure to use the "," to separate them. {english oh}. Do not use spaces.
$ ("# Mydiv div") obtain all div elements under the div id = "mydiv;
View sourceprint? 1 <div id = "mydiv">

2 <div class = "divs">
View sourceprint? 1. I'm the first
View sourceprint? 1 <div class = "divs">
View sourceprint? 1. I got it on the second floor.
View sourceprint? 1 </div>
View sourceprint? 1 </div> <BR> </div>

$ ("# Mydiv> li") Get the direct li sub-element under the div
The sub-element directly refers to the second-level element of the subset element below.
Here we will also mention a small concept called "JQuery iteration". What I understand is "loop". Do you have any other instructions? Please tell me
Continue tomorrow ..................
Welcome .................

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.