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