Home > Article > Web Front-end > How does jquery get how many tds there are in tr?
Jquery method to get how many td elements there are in tr: 1. Use the "$('td')" statement to match the td element; 2. Use the size() method to get the number of matching td elements, and you can get The number of td elements in the tr element, the syntax is "$('td').size();".
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.
jquery method to get several TDs in tr
1. Create a new html file, named test.html, for explanation How to get the number of td in tr in the table with jquery. Only after introducing the jquery.min.js library file and successfully loading the file can you use the methods in jquery. Use table, tr, and td tags to create a table with two rows and two columns, and set the table border to 1px.
In the test.html file, use the button tag to create a button with the name of "Get the number of TDs". Bind the onclick click event to the button button. When the button is clicked, the getnum() function is executed.
2. In the js tag, create the getnum() function. Within the function, obtain the cell object of the table through the td element name, and use the size() method. Get the number of td in tr, and finally, use the alert() method to output the number of td.
#Open the test.html file in the browser, click the button to view the obtained value.
Summary:
1. Create a test.html file.
2. In the file, use table, tr, and td tags to create a table with two rows and two columns, and create a button button to trigger the execution of the js function.
3. In the js tag, create a function. Within the function, by obtaining the td element object, use the size() method to obtain the number of td in tr.
Note
The size() method is also suitable for obtaining the number of tr rows.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of How does jquery get how many tds there are in tr?. For more information, please follow other related articles on the PHP Chinese website!