JQuery selector Style

Source: Internet
Author: User

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.

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.