The difference between dom.getattribute ("value") and Dom.value in JavaScript

Source: Internet
Author: User

Dom is an input type= "text"
Manually modifying the value of input, using Dom.getattribute ("value") can only get the value in the HTML DOM, but not the modified value (that is, the value in memory);
The most recent value (in-memory value) that can be modified by dom.value
Use: Dom.setattribute ("Value", "2011"), can only be obtained by Dom.getattribute ("value") 2011
Use: Dom.value = 2012, only 2012 can be obtained by dom.value
That is to say: GetAttribute and SetAttribute is a set, the direct use of attributes is a set, two sets of completion is not the same thing.

Summarize:
1. If it is a custom attribute, use GetAttribute, SetAttribute, and maintain browser compatibility.
2. If it is a DOM attribute, use it directly to get the latest value.
3. JQuery's underlying method $.fn.val () uses the Dom.value property.
Custom properties are best used with getattribute, SetAttribute.

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.