Properties and CSS sections in the jquery Handbook

Source: Internet
Author: User

Properties:1, attr (NAME|PROPERTIES|KEY,VALUE|FN)

Sets or returns the property value of the selected element.

Parameter name Description: Returns the SRC attribute value for all images in the document. $ ("img"). attr ("src");
Parameter Properties Description: Sets the SRC and ALT attributes for all images. $ ("img"). attr ({src: "test.jpg", alt: "Test Image"});
Parameter Key,value Description: Sets the SRC attribute for all images. $ ("img"). attr ("src", "test.jpg");
Parameter key, callback function Description: Sets the value of the SRC attribute to img1.png, ...    $ (function () {        ///callback function (index subscript) (Src1 can be customized, is the value of the SRC attribute)        $ (' img '). attr (' src ', function (INDEX,SRC1) {        THIS.SRC = "img" + (index+1) + ". png";        })    Result:      src= "img1.png"      src= "img2.png"      src= "Img3.png"      ...
2, Removeattr (name)

Remove an attribute from each matching element

Remove the src attribute of the image in the document $ ("img"). Removeattr ("src");

3, prop (NAME|PROPERTIES|KEY,VALUE|FN)

Gets the property value of the first element in the matching element set.

The parameter name Description:   //check box is true and is not checked for false$ ("input[type= ' checkbox ']"). Prop ("checked");    Parameter Properties Description:       //Disables all check boxes on the page.    $ ("input[type= ' checkbox ']"). Prop ({disabled:true});        Parameter Key,value Description:           //Disable and select the check box on all pages.      $ ("input[type= ' checkbox ']"). Prop ("disabled", false);      $ ("input[type= ' checkbox ']"). Prop ("checked", true);            Parameter key, callback function Description:              //  function to set the check box on all pages is selected.                  <input type= "checkbox"  name= "" id= "" value= ""/>  //results, check tick on              <input type= "checkbox" Checked= "Checked" name= "id=" "value=" "/>    //results, not on              <input type=" checkbox "checked=" Checked "name=" " Id= "" value= ""/>    //result, not checked on            $ ("input[type= ' checkbox ')". Prop ("Checked", function (I, Val) {              return!) val;            });  

  

4, Removeprop (name)

Used to delete a property set set by the. Prop () method


5, AddClass (CLASS|FN)

Adds the specified class name for each matching element.

Parameter class Description:    add ' selected ' Class $ ("P") to the matched element. AddClass ("selected"); $ ("P"). addclass ("selected1 selected2");
callback function Description:    add a "item-2" class to the last-class <ul>      <li>Hello</li>      <li>Hello</li>      <li>hello</li></ul>$ (' ul li:last '). addclass (function () {  return ' item-' + $ (This). Index ( );});

  

6. Return value: Jqueryremoveclass ([CLASS|FN])

Removes all or the specified class from all matching elements.

Parameter class Description:   remove the ' Selected ' Class $ ("P") from the matching element. Removeclass ("selected");//Parameter Class Description:    Delete all classes of matching elements $ ("P"). Removeclass ();//callback function Description:    delete class$ (' Li:last ') on the last element with previous duplicates. Removeclass (function () {    return $ (this). Prev (). attr (' class ');});

   

7, Toggleclass (CLASS|FN[,SW])

Delete (add) A class if it exists (does not exist).

Parameter class Description:    toggles the ' selected ' Class $ ("P") for the matching element. Toggleclass ("selected");//Parameter Class,switch Description:    add once per click ' Highlight ' Class    <strong>jquery code:</strong>  var count = 0;  $ ("P"). Click (function () {      $ (this). Toggleclass ("Highlight", count++% 3 = = 0);  }); /callback Function Description:    sets the Class property $ (' Div.foo ') according to the parent element. Toggleclass (function () {  if (). Parent (). is ('. Bar ') {    return ' happy ';  } else {    return ' sad ';}  });

  

8. HTML ([VAL|FN])

Gets the HTML content of the first matching element. This function cannot be used with XML documents. But it can be used in XHTML documents.

In an HTML document, we can use the. html () method to get the contents of any one element. If the selector matches more than one element, only the HTML content of the first matching element is fetched.

No parameter description:    returns the contents of the P element. $ (' P '). html ();//Parameter Val Description:    Sets the contents of all P elements $ ("P"). html ("Hello <b>world</b>!"); callback function Description: Use a function to set the contents of all matching elements. JQuery Code: $ ("P"). The index of the P element of the HTML (function (n) {    return) is: "+ N;    }";

 

9. Text ([VAL|FN])

Gets the contents of all matching elements.

The result is text that is combined with the text content contained by all matching elements. This method is valid for both HTML and XML documents.

 

No parameter description:    returns the text content of the P element. $ (' P '). text ();//Parameter Val Description:    sets the textual content of all P elements $ ("P"). Text ("Hello world!"); /callback Function Description:    Use the function to set the text content of all matching elements. $ ("P"). Text (function (n) {    return) the index of the P element is: "+ N;    }";

  

10. Val ([Val|fn|arr])

Gets the current value of the matching element.

In JQuery 1.2, you can return the value of any element. Includes select. If multiple selections, an array is returned that contains the selected value.

No parameter description:    Gets the value of the text box in $ ("input"). val ();//Parameter Val Description:    Sets the value of the text box to $ ("input"). val ("Hello world!"); /callback Function Description:    Sets the value of the text box to $ (' Input:text.items '). Val (function () {  return this.value + "+ this.classname;}); /parameter array description:    check check2,radio1<input type= "checkbox" value= "Check1"/> check1<input type= "checkbox" value= "Check2"/> check2<input type= "Radio" value= "Radio1"/> radio1<input type= "Radio" value= "Radio2"/> radio2$ ("Input"). Val (["Check2", "Radio1"]);

  

CSS Section11. CSS (NAME|PRO|[,VAL|FN])

Accesses the style properties of the matching element.

Parameter name Description:    Gets the value of the color style property of the first paragraph. $ ("P"). CSS ("color");//Parameter Properties Description: The    font color of all paragraphs is set to red and the background is blue. $ ("P"). css ({"Color": "#ff0011", "Background": "Blue"});//Parameter Name,value Description:    set all paragraph fonts to red $ ("P"). CSS ("Color", "red") ;//Parameter name, callback function description:    gradually increase the size of the div (  "div"). Click (function () {    $ (this). css ({      width:function (index), Value) {        return parsefloat (value) * 1.2;      },       height:function (index, value) {        return parsefloat (value) * 1.2;      }    );  

 

 

12, Jquery.csshooks

Add hooks directly to JQuery to override the method used to set or get specific CSS properties in order to standardize CSS property names or create custom properties.

The $.csshooks object provides a way to get or set a specific CSS value by defining a function. You can use it to create new csshooks for standardizing CSS3 functions, such as Box shadows and gradients (gradients).

For example, some Webkit-based browsers use-webkit-border-radius to set the object's Border-radius, whereas earlier versions of Firefox use-moz-border-radius. Csshook can standardize these different formulations so that. css () can use a uniform normalized property name (Border-radius or the corresponding DOM attribute Borderradius).

In addition to providing a more granular approach to the processing of a particular style, the $.csshooks also extends the set of properties on the. Animate () method.

 

13. Offset ([coordinates])

Gets the relative offset of the matching element at the current viewport.

The returned object contains two integer properties: Top and left, measured in pixels. This method is valid only for visible elements.

Gets the offset of the second paragraph <p>hello</p><p>2nd paragraph</p>var p = $ ("p:last"); var offset = P.offset ();p. HTML ( "Left:" + Offset.left + ", Top:" + offset.top);

  

14, Position ()

Gets the offset of the matching element relative to the parent element.

The returned object contains two integer properties: Top and left. To calculate the results accurately, use pixel units on the padding, border, and fill properties. This method is valid only for visible elements.

Gets the offset of the first paragraph <p>hello</p><p>2nd paragraph</p>var p = $ ("P:first"); var position = P.position (); $ ( "P:last"). HTML ("Left:" + Position.left + ", Top:" + position.top);

  

15. ScrollTop ([Val])

Gets the offset of the match element at the top of the scroll bar.

This method is valid for both visible and hidden elements.

No parameter description:    //Gets the offset of the first paragraph relative to the top of the scrollbar <p>hello</p><p>2nd Paragraph</p>var p = $ ("P:first"); $ ("P: Last "). Text (" ScrollTop: "+ p.scrolltop ());//Result: <p>hello</p><p>scrolltop:0</p>//parameter val Description:      //sets the offset $ ("Div.demo") relative to the top of the scroll bar. scrolltop (300);

 

16. ScrollLeft ([Val])

Gets the offset to the left of the matching element relative to the scrollbar.

This method is valid for both visible and hidden elements.

No parameter description:   //Gets the offset of the first paragraph relative to the left of the scrollbar <p>hello</p><p>2nd Paragraph</p>var p = $ ("P:first"); $ ("P: Last "). Text (" ScrollLeft: "+ p.scrollleft ());//Parameter Val Description:   //Set offset $ (" Div.demo ") relative to the left of the scrollbar. ScrollLeft (300);

  

17, height ([val|fn])

Gets the height value (px) of the current calculation of the matching element.

After JQuery 1.2 can be used to get window and document the high

No parameter description:    //Gets the first paragraph of the high $ ("P"). Height ();//Parameter Val Description:   //Set the height of all paragraphs to 20:$ ("P"). Height (20);//Parameter function (index, height Description:  //  increase the height of the P element with a 10-pixel amplitude jquery code:  $ ("button"). Click (function () {    $ ("P"). Height (function (n,c) {    return c+10;    });  

  

18. Width ([val|fn])

Gets the width value (px) currently computed for the first matching element.

19, Innerheight ()

Gets the inner area height of the first matched element (including padding, excluding borders).

This method is valid for both visible and hidden elements.

Gets the inner area height of the first paragraph. <p>hello</p><p>2nd Paragraph</p>var p = $ ("P:first"); $ ("P:last"). Text ("Innerheight:" + P.innerheight ());

  

20, Innerwidth ()

Gets the inner area width of the first matched element (including padding, excluding borders).

This method is valid for both visible and hidden elements.

21. Outerheight ([options])

Gets the outer height of the first matching element (including padding and borders by default).

This method is valid for both visible and hidden elements.

Gets the outer height of the first paragraph. <p>hello</p><p>2nd Paragraph</p>var p = $ ("P:first"); $ ("P:last"). Text ("Outerheight:" + P.outerheight () + ", Outerheight (True):" + P.outerheight (true));

  

22. Outerwidth ([options])

Gets the outer width of the first matching element, including padding and borders by default.

This method is valid for both visible and hidden elements.

 

  

Properties and CSS sections in the jquery Handbook

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.