Document common attributes and attributes collection

Source: Internet
Author: User


The last blog post said that when deleting the node information, there is a line of code document.body.removeChild (deletenode), what is document.body ? What's the relationship between body and document? Today, talk about common document properties and collection properties. The so-called document attribute refers to the single attribute information, which refers to a single object, and the collection property refers to those sub-objects within the document object that can be grouped together.


Document.title



The above code, after the page loading is complete, play an alert box out, what is the content of the surface?

Do the following to see the results

   

pops up the title content, which means that document.title points to the content of the title tag in the HTML page.

Make a breakpoint to see what else is the document property information?

Breakpoint hit alert (Document.title), line, and document monitoring


Expand the Document object to see


There are too many properties and collection properties for document, so let's take a look at these briefly.


Document.bgcolor


Like Document.bgcolor, which represents the background color, the current value is the hexadecimal representation of the #ffffff, we add a background color to the page, and then print the background color to see if the code is modified to


Pop-up box effect is


document.anchors


The properties of a collection class Document.anchors gets the collection of all the hyperlinks


Popup Box value is 3


The strange thing about this example is that the hyperlink must have the name attribute added to Document.anchors to get to the hyperlink, otherwise document.anchors gets the collection as an empty collection. If you know a friend, you can say the reason.

document.forms

Look at a collection property document.forms get the collection of all form forms


The popup value is 2, and in the example there are two form forms.

Get a single object method in a Collection class property

And then the above code, if we want to get the id attribute value of the first form form, how to get it?

The result of a collection class property is a collection, which can be obtained by means of an array subscript,

That

var forms = Document.forms;for (i=0; i<forms.length; i++) {alert (forms[i].id);}

Next, we break down the collection properties.


You can see the item () method in which the Item method passes a parameter that is the ordinal of the object in the collection

Will alert (forms[i].id); Modified to alert (Forms.item (i). ID); The same effect.


Basically, the collection properties are accessed in both ways, and if more problems are encountered in the development, and if you want to get more access, see what you can do with the breakpoint above, and then try to find a way to start the problem.


Document common attributes and attributes collection

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.