jquery gets and changes element attribute values

Source: Internet
Author: User

The property of the tag is called the element attribute, and the corresponding property of the DOM object in JS is called the DOM attribute. The DOM attribute name in JS is sometimes different from the original element property name.

================================== Action Element Properties ==================================

Returns an element that specifies a property value

var txt1_val=$ ("#txt1"). attr ("value");

Changing DOM property values through the DOM property name of an element

$ ("#txt1"). attr ({value: "Txt1_value", ClassName: "Txt1_class"});

changing element property values by specifying element properties

$ ("#txt1"). attr ("Class", "Txt1_class2");

Assigns a value to the specified element property, returning the value by the method that is bundled later

$ ("#txt1"). attr ("Class", function () {

return "TXT1_CLASS3";

})

Removes the specified element property

$ ("#txt1"). Removeattr ("class");

jquery gets and changes element attribute values

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.