Add and remove attributes that are de-removed as ' color ':
$(‘button‘).click(function () {
var $x = $(‘div‘)
$x.prop(‘color‘, ‘f00‘)
$x.append(‘The color Attributes:‘ + $x.prop(‘color‘))
$x.removeProp(‘color‘)
})
The prop () method sets or returns the attributes and values of the selected element.
Returns the value of the first matching element when a property value is returned;
When setting property values, set one or more property/value pairs for the matching element collection
Note:
the prop () method should be used to retrieve property values , such as DOM properties;
To retrieve HTML attributes, use the attr () method instead;
To remove an attribute, use the Removeprop () method
eg:
returns the value of the property : $ (selector). Prop (the name of the specified property)
set properties and Values : $ (selector). Prop (the name of the specified property, the value of the specified property)
use functions to set properties and values : $ (selector). Prop (Specifies the name of the property, function (retrieves the index position of the element in the collection, retrieves the current property value of the selected element))
set multiple properties and values : $ (selector). Prop ({The name of the specified property: The value of the specified property, the name of the specified property: The value of the specified property, ...})
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.