Self-study notes for jquery beginners (3)

Source: Internet
Author: User
63. Set a calculated attribute value for all matching elements
$ (IMG). ATTR ("title", function () {return this. SRC });
64. Set an attribute value for all matching elements
$ ("IMG"). ATTR ("src", "test.jpg ");
65. Obtain the attribute value of the First Matching Element. This method can be used to conveniently obtain the value of an attribute from the First Matching Element.
If the element does not have a property, undefined is returned.
$ ("IMG"). ATTR ("src ");
66. Set an object in the form of "name/value" to attributes of all matching elements.
$ ("IMG"). ATTR ({SRC: "test.jpg", alt: "testimage "});
67. delete an attribute from each Matching Element
$ ("IMG"). removeattr ("src ");
68. Add the specified class name for each Matching Element
$ ("Div"). addclass ("selected ");
69. Delete All or specified classes from all matching elements
Delete all classes for matching elements: $ ("Div"). removeclass ();
Delete the specified class: $ ("Div"). removeclass ("selected ");
70. Delete (ADD) a class if it exists (does not exist)
$ ("Div"). toggleclass ("selected ");
71. Obtain the HTML content of the First Matching Element. This function cannot be used in XML documents. But it can be used in XHTML documents.
$ ("Div" pai.html ();
72. Set the HTML content of each matching element. This function cannot be used in XML documents. But it can be used in XHTML documents.
$ ("Div" pai.html ("<p> hello, my friend </P> ");
73. Obtain the content of all matching elements. The result is a combination of text content containing matching elements.
$ ("Div"). Text ();
74. set text content for all matching elements
$ ("Div"). Text ("<B> good </B> morning ");
75. Obtain the current value of the First Matching Element. In jquery 1.2, the value of any element can be returned. Including select. If multiple values are selected, an array containing the selected values is returned.
$ ("Input"). Val ();
$ ("P"). append (
"<B> Single: </B>" + $ ("# single"). Val () +
"<B> multiple: </B>" + $ ("# multiple"). Val (). Join (",")
);
76. Check, select, and radio can all be used to assign values to them.
$ ("# Single"). Val ("single2 ");
$ ("# Multiple"). Val (["multiple2", "multiple3"]);
$ ("Input"). Val (["check2", "radio1"]);
77. Set the value of each matching element. In jquery 1.2, this can also assign values to the select element.
$ ("Input"). Val ("Hello world! ");
78. Obtain the nth element. The position of this element starts from 0.
$ ("Div"). eq (1 );
79. filter out the set of elements that match the specified expression. This method is used to narrow the matching range. Multiple Expressions separated by commas
$ ("Div"). Filter (". Selected ");
80. filter out the set of elements that match the returned values of the specified function. This function calculates each object once.
(As '$. Each'). If the called function returns false, the element is deleted. Otherwise, the element is retained.
$ ("Div"). Filter (function (INDEX ){
Return $ ("P", this). Length = 0;
});
81. Check whether the current element contains a specific class. If yes, true is returned.
This is actually is ("." + class ).

$ ("Div"). Click (function (){
If ($ (this). hasclass ("protected ")){
$ (This)
. Animate ({left:-10 })
. Animate ({left: 10 })
. Animate ({left:-10 })
. Animate ({left: 10 })
. Animate ({left: 0 });
}
});
82. Use an expression to check the selected element set. If at least one element matches the given expression, true is returned.
If no element matches, or the expression is invalid, 'false'. 'filter' is actually called internally. Therefore, the original rules of the filter () function are also applicable here.

$ ("Input [type = 'checkbox']"). Parent (). Is ("form ");
83. convert a group of elements into other arrays (whether or not they are element arrays)
You can use this function to create a list, whether it is a value, attribute, CSS style, or other special form. You can use '$. Map ()' to create a map.

$ ("P"). append ($ ("input"). Map (function (){
Return $ (this). Val ();
}). Get (). Join (","));
84. Delete elements that match the specified expression
$ ("P"). Not ($ ("# selected") [0]);
85. Select a matched subset, which is similar to the original slice method.
$ ("P"). Slice (0, 1). wraplnner ("<B> </B> ");

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.