[Original] Book notes of sharp jquery (2)

Source: Internet
Author: User
Iii. jquery Dom operations

1. DOM: Document Object Model

2. Dom classification: Dom core, HTML Dom, and CSS dom

3. Create a node:

VaR $ li_1 = $ ("<li Title = 'bananas '> bananas </LI> ");

$ ("Ul"). append ($ li_1 );

 

4. Insert nodes

<1> append () Internal Append content

<2> appendto () append ()

<3> prepend () Internal content

<4> prependto () prepend () Inverse Operation

<5> after () External Append content

<6> insertafter () after anti-operation

<7> before () external front content

<8> insertbefore () before Inverse Operation

5. delete a node

Remove () delete a node

Empty () clears node content

6. Copy nodes

Clone ()

 

7. Replace nodes

Replacewith ()

Replaceall () ---- reverse operation of replacewith ()

 

8. Package nodes

Wrap () -- Example $ ("strong"). Wrap ("<B> </B> ")

Wrapall ()

Wrapinner ---- label content package

 

9. Attribute operations

[1] Get attributes

VaR P = $ para. ATTR ("title ");

[2] setting properties

$ Para. ATTR ("title", "yourtitle ")

$ Para. ATTR ({"title": "yourtitle", "name": "test"}) Multiple

[3] deleting attributes

$ ("P"). removeattr ("title ");

 

10. style operations

[1] Get class

VaR p_class = $ ("p"). ATTR ("class ");

[2] set the class

$ ("P"). ATTR ("class", "high ");

[3] append class

$ ("P"). addclass ("another ");

[4] Remove a style

$ ("P"). removeclass ("high"); remove a single style

$ ("P"). removeclass ("high anther"); remove multiple styles

[5] switching styles

If the toggleclass () class name exists, delete it. If it does not exist, add

[6] determine whether a style exists

$ ("P"). hasclass ("anther") is equivalent to $ ("p"). Is (". Anther ")

 

11. Set and obtain html

[1] HTML (): Get, Set

[2] Text (): Get, Set

(3) Val (): Get, set, select the drop-down list, multiple selection box, and single-Choice

 

12. Traverse nodes

[1] children () child element (excluding child element)

[2] Next () gets the peer element next to it

[3] Prev () is used to obtain the peer element adjacent to the previous one.

[4] siblings () obtains all peer Elements

[5] closet () obtains the nearest Matching Element.

 

13. CSS-DOM operation

[1] Get the style

VaR color = $ ("p" ).css ("color ");

[2] set a single style

$ ("P" ).css ("color", "Red ");

[3] set multiple styles

$ ("P" ).css ({"fontsize": "30px", "backgroundcolor": "#888 "});

 

Author: Tony Zhao

Source of this article: http://www.cnblogs.com/ytaozhao copyright belong to the author and blog Park, welcome to reprint, but without the author's consent must retain this paragraph of the statement, and inArticleThe original text connection is clearly displayed on the page. Otherwise, the legal liability is retained.

 

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.