Difference between getelementsbytagname and $ (é lement)

Source: Internet
Author: User

The getelementsbytagname of JS and $ (élement) of JQ both get the elements in Dom, but they also have some differences and paste the Code:

VaR El = Document. getelementsbytagname ('P ');
VaR P = '<P class = "AA"> </P> ';
$ ('Body'). append (P );
Console. Log (El. Length) // P Tag Length + 1;

 

VaR El = $ ('P ');
VaR P = '<P class = "AA"> </P> ';
$ ('Body'). append (P );
Console. Log (El. Length) // The length of the P tag is the original Dom length.

 

In this way, we can see that when an element is added to the Dom, The getelementsbytagname set automatically updates the number of elements, while $ (é lement) is still the snapshot of the original element set.

Difference between getelementsbytagname and $ (é lement)

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.