One JavaScript instance every day-get the current height of the element, javascript instance

Source: Internet
Author: User

One JavaScript instance every day-get the current height of the element, javascript instance

<! DOCTYPE html> 


Element Acquisition in javascript

Id is unique, that is, an id of the same name is not allowed to exist on the same page. Therefore, when an id is used to obtain a webpage element, a single element is obtained, not an array, therefore, you do not need to add [0], for example:
GetElementById ("abc ")
The names or tagnames allow the same name. Therefore, the webpage elements obtained through them are arrays (even if the same name does not exist, only one is an array ), to call one of the elements, such as the first one, you must add [0]. For example:
GetElementsByName ("kkk") [0]
GetElementsByTagName ("kkk") [0]

In fact, from the front of By, you know which one needs to be added [0] and which does not need to be added.

In addition, your getElementByTagName is incorrect, with a missing s

Element Acquisition using javascript

If getElementByTagName does not have this method, it should be getElementsByTagName.

GetElementsByTagName returns an array

[0] should be added, but in javascript, sometimes the array itself can also represent the first element of the array.
But this is not a good habit! [0]

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.