
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Count Number of Columns in a Table with jQuery
To count number of columns in a table with jQuery, use the each() function with attr(). You can try to run the following code to learn how to count column in a table:
Eaxmple
<html> <head> <title>jQuery Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ var num = 0; $('tr:nth-child(1) td').each(function () { if ($(this).attr('colspan')) { num += +$(this).attr('colspan'); } else { num++; } }); alert("Total Columns= "+num); }); </script> </head> <body> <table> <tr> <td>-1st column-</td> <td colspan="1">-2nd column-</td> <td colspan="1">-3rd column-</td> <tr> </table> </body> </html
Advertisements