Home  >  Article  >  Web Front-end  >  How does jquery get how many tds there are in tr?

How does jquery get how many tds there are in tr?

WBOY
WBOYOriginal
2021-11-16 17:24:223994browse

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();".

How does jquery get how many tds there are in tr?

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.

How does jquery get how many tds there are in tr?

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.

How does jquery get how many tds there are in tr?

#Open the test.html file in the browser, click the button to view the obtained value.

How does jquery get how many tds there are in tr?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn