JQuery selector Style
. Attr () and. removeAttr ()
Each element has one or more features. The purpose of these features is to provide additional information about the corresponding element or its content. For example, in an img element, src is a feature of the element used to mark the image address.
There are three DOM methods for operating features: getAttribute method, setAttribute method, and removeAttribute method. There are still many problems in actual operations. In jQuery, you can use an attr () and removeAttr (), including compatibility issues.
In jQuery, the attr () method is used to obtain and set element attributes. attr is the abbreviation of attribute. attr () is often used in jQuery DOM operations ()
Attr () has four expressions
RemoveAttr () deletion method
. RemoveAttr (attributeName): removes an attribute from each element in the matched element set)
Advantages:
Attr and removeAttr are all encapsulated by jQuery for Attribute operations. This method is called directly on a jQuery object and attributes can be operated easily, you do not need to understand the issue of different browser attribute names.
Notes:
There is a concept difference in dom: Attribute and Property are translated as "attributes", and js advanced programming is translated as "Features" and "attributes ". Simply put, Attribute is the built-in Attribute of the dom node.
For example, id, class, title, and align commonly used in html:
<Div id = "immooc" title = "MOOC"> </div>
And Property is the DOM element as the object, and its appended content, such as tagName, nodeName, nodeType, defaultChecked, and defaultSelected use. prop () method for value or value assignment.
To get Attribute, you need to use attr. To get Property, you need to use prop.