Custom properties of any node within the "JavaScript" body

Source: Internet
Author: User

Any node within the body in HTML can be custom-defined, not including body, of course,

For example, the following code:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

I can define a custom attribute III for an in-line position with ID s, with a value of 222, and it is obvious that III is not the basic attribute of the span element or even any other element, that is, those id,style, and so on, so there is no effect on the performance of the things within this node, But what is the point of doing this?

This is primarily used to provide JavaScript with further action. Sometimes, an HTML is not as simple as the above, with a dynamic Web language php,jsp,asp.net Everything becomes complicated, you can set a label to the node you want to manipulate, through getattribute and setattribute operation. For example, write the following script for the above HTML page:

<script>var Span=document.getelementbyid ("s"), Alert (S.getattribute ("III") + ""), S.setattribute ("III", " 2222121 "), Alert (S.getattribute (" III ") +" ");</script>
Get the span node first, and then get its attribute value, and you must force the value of this property to be converted to a string to be able to eject normally.

The value of the III property of the span node is then set to 2222121 and then ejected.

Operating effects such as:



Custom properties of any node within the "JavaScript" body

Related Article

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.