Home >Web Front-end >JS Tutorial >jquery gets the implementation code of custom attributes (attr and prop)_jquery
1. attr (attribute name) //Get the value of the attribute (get the attribute value of the first matching element. This method can easily get the value of an attribute from the first matching element. If the element does not have a corresponding attribute, then Return undefined )
2. attr(attribute name, attribute value) //Set the value of the attribute (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, namely: {Attribute name one: "Attribute value one", Attribute name two: "Attribute value two", ... }. (This is the best way to set many attributes in batches across all matching elements. Note that if you want 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:
What is your favorite fruit?