Here’s an example code snippet:
// Get the <tr> element var tr = document.querySelector('tr'); // Get an array of all the <td> elements within the <tr> var tds = tr.querySelectorAll('td'); // Get the number of <td> elements within the <tr> var numTds = tds.length; console.log(numTds); // Output the number of <td>s
In this example, the querySelector method is used to select the first element in the document, but you can adjust the selector to match the specific you want to count s in.
The querySelectorAll method is used to get an array of all elements within the selected . The length property of the resulting array is then used to get the number of elements.
Note that this code assumes there is only one element on the page with child elements. If there are multiple elements, you may need to adjust the code to select the specific you want to count s in.
- - Adding and removing content in jQuery
- - Can I change the Dojo namespace to something other than dojo
- - How can I upload files asynchronously with jQuery
- - How do you capture mouse events in firefox
- - How to auto-size an iFrame