JavaScript image library _ javascript tips for reading notes in JavaScriptDOM programming Art

Source: Internet
Author: User
This article mainly introduces the JavaScript image library of reading notes in JavaScriptDOM programming Art. if you need it, you can refer to the following two methods to change the src attribute of the image:

1. the setAttribute method is an integral part of "level 1st DOM". it can be used to set any attribute of an element node.

2, element. src = source; this is the method before "level 1st DOM" appears, and it is valid now.

The advantage of "level 1st DOM" is its portability. old methods only apply to Web documents, and DOM applies to any markup language.

Event Processing Functions

When clicking a link, I want to stay on this page rather than go to another window. the code is as follows:

The code is as follows:


Click

When you click this link, because the value returned by the Javascript code triggered by the onclick event handler is false, the default behavior of this link is not triggered.

ChildNodes attributes

The childNodes attribute can be used to obtain all child elements of any element. The array returned by the childNodes attribute contains all types of nodes, not just element nodes. In fact, almost everything in the document is a node, and even space and line breaks are interpreted as nodes, all of which are included in the array returned by the childNodes attribute.

However, each node has the nodeType attribute. The nodeType attribute has a total of 12 optional values, but only three of them are useful: the nodeType attribute value of the element node is 1, and the nodeType attribute value of the attribute node is 2, the value of nodeType for a text node is 3.

To change the value of a text node, use the nodeValue attribute provided by DOM.

The array element childNodes [0] has a more intuitive and readable synonym, which can be written as firstChild; DOM also provides a corresponding lastChild attribute.

Example:

The code is as follows:


Choose an image


First, create a variable to store it:

The code is as follows:


Var description = document. getElementById ("description ");

The return value of description. nodeValue is null.

The nodeValue attribute of the element itself is a null value.

The value of the text contained in the element. use description. childNodes [0]. nodeValue or description. firstChild. nodeValue.

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.