In jquery, the attr () method is used to obtain and set element attributes. attr is the abbreviation of attribute. attr () and attr () are often used in jQueryDOM operations () there are 4 expressions $ ("form "). attr ("check"); $ ("form "). prop ("check"); both of them are acceptable, but the new version of jquery recommends the second one. Both of them are similar in other aspects. The only difference I found is that in checkbox, you need to use prop, otherwise IE browser will be incompatible
The Code is as follows:
Script
Script
// Var J = $ ("p [lang]"). get ();
// Alert ($ ("[data-url]: eq (2)"). attr ("data-url "));
$ ("[Data-url]"). each (function (){
Alert ($ (this). attr ("data-url "));});
// $ ("[Data-url]"). each (function (){
// Alert ($ (this). prop ("data-url "));//});
Script
Appendix: jquery attr () method
In jquery, the attr () method is used to obtain and set element attributes. attr is the abbreviation of attribute. attr () and attr () are often used in jQuery DOM operations () there are four expressions.
1.Attr (Attribute name)// Obtain the attribute value (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. Undefined is returned if the element does not have an attribute)
2.Attr (Attribute name, attribute value)// Set the attribute value (set an attribute value for all matching elements .)
3.Attr (Attribute name,Function value)// Set the function value of the attribute (set a calculated attribute value for all matching elements. Instead of providing a value, a function is provided, and the value calculated by this function is used as the attribute value .)
4.Attr (properties) // Set multiple attribute values for the specified element, that is, {attribute name 1: "attribute value 1", attribute name 2: "attribute value 2 ",... ... }. (This is the best way to set multiple attributes in batches among all matching elements. Note: To set the class attribute of an object, you must use 'classname' as the attribute name. Or you can directly use 'class' or 'id '.)
Sample Code:
The Code is as follows:
Attr () method in jquery