JQ properties and CSS partial tests

Source: Internet
Author: User
Tags set set

1, attr (NAME|PROPERTIES|KEY,VALUE|FN) Sets or returns the attribute value of the selected element.

<Divclass= "attr">Sets or returns the property value of the selected element.</Div>    <Script>        $(". attr"). HTML ($ (". attr"). HTML ()+$(". attr"). attr ("class")); </Script>

2. REMOVEATTR (name) removes an attribute from each of the matched elements

<Divclass= "Removeattr"ID= "ABC">Remove an attribute from each matching element</Div>    <Script>        $(". Removeattr"). Click (function(){            $( This). Removeattr ("ID"); })    </Script>

3, prop (NAME|PROPERTIES|KEY,VALUE|FN) Gets the property value of the first element in the matching element set.

$ ("input[type= ' checkbox ']"). Prop ("checked");

4, Removeprop (name) is used to delete the property set set by the. Prop () method

$ (". P01"). Removeprop ("Disabled");

5, AddClass (CLASS|FN) adds the specified class name for each matching element.

$ ("option"). AddClass ("selected");

6, Removeclass ([CLASS|FN]) removes all or the specified class from all matching elements.

$ ("option"). Removeclass ("selected");

7, Toggleclass (CLASS|FN[,SW]) Delete (add) A class if it exists (does not exist).

$ ("option"). Toggleclass ("selected");

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.

$ (' P '). html (); Get content

9. Text ([VAL|FN]) Gets the contents of all matching elements.

$ (' P '). text ();

10, Val ([Val|fn|arr]) obtains the current value of the matching element.

$ ("input"). val (); typically used to get form elements

11. CSS (NAME|PRO|[,VAL|FN]) accesses the style attributes of the matching element.

$ ("P"). css ({"Color": "#ff0011", "Background": "Blue"});

12. Jquery.csshooks adds 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.

(function ($) {    //First, check to see if Csshooks is supported    if (!$.csshooks) {      //if not, output an Erro R message      throw ("JQuery 1.4.3 or above is required for the plugin to work");      return;    }      $.csshooks["Somecssprop"] = {      get:function (elem, computed, extra) {        //handle getting the CSS property      },< C11/>set:function (Elem, value) {        //handle Setting the CSS value      }    };  }) (jQuery);  The purpose is to unify the standard of some prefixes, so that the CSS can be used without prefix to be compatible.

13, offset ([coordinates]) gets the relative offset of the matched 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.

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.

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 matching element at the top of the scroll bar.

var p = $ ("P:first"); $ ("P:last"). Text ("ScrollTop:" + p.scrolltop ());

16, ScrollLeft ([Val]) Gets the offset of the matching element to the left of the scroll bar.

var p = $ ("P:first"); $ ("P:last"). Text ("ScrollLeft:" + p.scrollleft ());

17, height ([VAL|FN]) Gets the height value (px) of the current calculation of the matching element.

$ ("button"). Click (function () {    $ ("P"). Height (function (n,c) {    return c+10;    });  }); Returns a function for setting the height. Receives the index position of the element and the element's old height value as an argument.

18. Width ([VAL|FN]) Gets the width value (px) of the first matching element currently computed.

$ ("P"). width ();

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

$ (". P01"). Innerheight ();

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

$ (". P01"). Innerwidth ();

21. Outerheight ([options]) Gets the outer height of the first matching element (including padding and borders by default).

$ (". P01"). Outheight ();

22. Outerwidth ([options]) Gets the outer width of the first matching element (including padding and borders by default).

$ (". P01"). Outwidth (); they can all pass a true, counting the margins.

JQ properties and CSS partial tests

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.