"JavaScript DOM programming Art" notes

Source: Internet
Author: User
Tags tag name

The first few chapters introduce the basics of JavaScript, the declaration of variables, the functions, and the objects that are the focus, of course, no difficulty.

Chapter three begins with the emphasis, and the DOM.

D: Documentation

O: Object-oriented

M: Model (tree)

Get element:

There are three DOM methods that can get element nodes, respectively, by element ID, by tag name, and by class name.

1.getElementById

Returns an identifier based on the ID

2.getElementByTagName

Returns an array of objects, based on the label name. Each object corresponds to a list item element in the Document object, respectively.

3.getElementByClassName

The above three methods are used to get the element, and after we get the element, we also need to get its various properties. The GetAttribute method is used to get the property, and the SetAttribute method is used to change the property.

GetAttribute is a function that has only one parameter and you intend to query the name of the property.

Object.getattribute (attribute)

The GetAttribute method is not part of the document object, so it cannot be called through the Document object. It can only be called through element nodes. For example, it can be combined with the Getelementbytag method. Gets the title property of each <p> element, as follows:

var paras = document.getelementsbytagname ("P");  for (var i = 0; i < paras.length;i++) {      alert (Paras[i].getattribute ("title"));}

"JavaScript DOM programming Art" notes

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.