Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Expand Table Rows Using jQuery, HTML And CSS

Tuesday, Jan 24, 2017

Tags:- jQuery HTML CSS

In this tutorial we will show you how to expand table rows using jQuery, HTML and CSS when user clicks on a row a box with some additional details will show and when user again clicks on that row box will hide.You may also like pricing table using HTML and CSS.

See Demo
Expand Table Rows Using jQuery, HTML and CSS

To Expand Table Rows It Takes Only Two Steps:-

  1. Make a HTML file and define markup and scripting
  2. Make a CSS file and define styling

Step 1.Make a HTML file and define markup and scripting

We make a HTML file and save it with a name expand_table.html

<link rel="stylesheet" type="text/css" href="table_style.css">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function show_hide_row(row)
<div id="wrapper">

<table border=1 id="table_detail" align=center cellpadding=10>


<tr onclick="show_hide_row('hidden_row1');"><td>Ankit</td><td>25</td><td>60000</td><td>Computer Programmer</td></tr>
<tr id="hidden_row1" class="hidden_row">
<td colspan=4>Ankit is 25 years old and he is a computer programmer he earns 60000 per month</td>

<tr onclick="show_hide_row('hidden_row2');"><td>Aarti</td><td>29</td><td>40000</td><td>Web Designer</td></tr>
<tr id="hidden_row2" class="hidden_row">
<td colspan=4>Aarti is 29 years old and she is a web designer he earns 40000 per month</td>

<tr onclick="show_hide_row('hidden_row3');"><td>Mohit</td><td>32</td><td>90000</td><td>Cyber Security Expert</td></tr>
<tr id="hidden_row3" class="hidden_row">
<td colspan=4>Mohit is 32 years old and he is a cyber security expert he earns 90000 per month</td>

<tr onclick="show_hide_row('hidden_row4');"><td>John</td><td>22</td><td>20000</td><td>Content Writer</td></tr>
<tr id="hidden_row4" class="hidden_row">
<td colspan=4>John is 22 years old and he is a content writer he earns 20000 per month</td>

<tr onclick="show_hide_row('hidden_row5');"><td>Mukesh</td><td>40</td><td>3,50000</td><td>Chief Executive</td></tr>
<tr id="hidden_row5" class="hidden_row">
<td colspan=4>Mukesh is 40 years old and he is chief executive he earns 3,50000 per month</td>



In this step we create a table and add 5 sample rows and 5 hidden rows one form each row to display addititonal details when user clicks on row a box with some additional details will show.We use jQuery toggle function to show hide the hidden row box.You may also like add, edit and delete rows from table dynamically.

Step 2.Make a CSS file and define styling

We make a CSS file and save it with a name table_style.css

 margin:0 auto;
 font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif;
 margin:0 auto;
#wrapper h1
#wrapper h1 p
 border-collapse: collapse;
#table_detail tr:hover
#table_detail .hidden_row

You can also view our sort table using jQuery to implement sorting in table.Thats all, this is how to expand table rows using jQuery, HTML and CSS.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH