How to use JavaScript to obtain the number of li in ul _ javascript tips-PHP source code

Source: Internet
Author: User
This article describes how to use JavaScript to obtain the number of lies in ul, and describes how to use javascript to obtain HTML elements on pages and perform attribute operations, for more information about how to use JavaScript to obtain the number of likes in ul, refer to the next article. This article describes how to use javascript to obtain HTML elements on pages and how to perform attribute operations. For more information, see

This example describes how to use JavaScript to obtain the number of li in ul. We will share this with you for your reference. The details are as follows:

There is such an HTML code:

 
 

  • The number is not fixed. now we need to use javascript to obtain the number of li.

    You can combine getElementById and getElementsByTagName to achieve the following:

    Temp = document. getElementById ('my‑usel'); lis = temp. getElementsByTagName ('Lil'); alert (lis. length); // display the number of li elements

    Or you can directly obtain:

    Lis = document. getElementById ('myusel'). getElementsByTagName ('Lil'). length; alert (lis); // display the number of li elements
  • 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.