Jquery document operations

Source: Internet
Author: User

Let's take an example of jquery's document operations today. The first example is as follows:

<! Doctype html >
< Html >
< Head >
< Style >

P{ Margin :8px ; Font-size : 16px ;   }
. Selected { Color : Blue ;   }
. Highlight { Background : Yellow ;   }
</ Style >
< Script SRC = "Http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" > </ Script >
</ Head >
< Body >
< P Title = "12335666" > Jquery document operations </ P >
< P > Example </ P >
< P > This is the test document. </ P >
< Script > Add JS here Code </ Script >
</ Body >
</ Html >

1) selector. addclass (classname), add the specified class name for each specified object
Code: $ ("P: First"). addclass ("heiglight"), the result is the first element < P > Jquery document operations </ P > Highlighted

2) selector. After (content) inserts content after each Matching Element

Code: $ ("P: First"). After ('<p> test of inserting the after function </P> ')

3) selector. append (content) inserts content at the end of each matching element. Unlike after, append inserts content inside the element, inserts child elements, and after inserts sibling elements.

4) The content. appendto (target) function is the same as append, but the parameter location is different. It is easy to see from the above method.

5) selector. ATTR (attributename) gets the first matching attribute name

. ATTR (attributename, value) sets one or more attributes for the specified element.

Or. ATTR (attributename, function (index, ATTR) {}) If selector is a set element, index indicates the index value, starting from scratch.

Code: $ ("P: Last"). Text ($ ("p"). ATTR ('title') the content of the Last P element is modified.

6) selector. Before (content) and after implement the opposite function, which is to insert content in front of the element outside.

7) selector. Clone () deeply copies all content, including elements, child elements, and text nodes.

Code: $ ("P: First"). Clone (). appendto ($ ('P: last'). This inserts the first element into the last P element.

8. selector.css (propertyname) to obtain the style attribute value of the first element in the element set.

. CSS (propertyname, value) sets one or more attributes for the matching element.

The functional design of CSS and ATTR is similar.

 

..

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.