Introduction:
Here I will explain how to use jQuery to merge multiple tables into a single table in Javascript or jQuery to merge two tables into single table.
Description:
In previous articles I explained jQuery check if string contains specific word, jQuery add border to images in webpage, jQuery show loading image in pageload, jQuery hide div elements after 5 seconds, jQuery convert am / pm time to 24 hours time, jQuery print div content with css and many articles relating to JQuery, JavaScript. Now I will explain how to merge two tables into single table using jQuery.
In previous articles I explained jQuery check if string contains specific word, jQuery add border to images in webpage, jQuery show loading image in pageload, jQuery hide div elements after 5 seconds, jQuery convert am / pm time to 24 hours time, jQuery print div content with css and many articles relating to JQuery, JavaScript. Now I will explain how to merge two tables into single table using jQuery.
To
merge two tables into single table we need to write the code like as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Merge Multiple Tables into single table in webpage</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function()
{
$('#btnMerge').click(function() {
$('#tbl1 >
tbody:last').append($('#tbl2 > tbody').html());
$('#tbl2').remove();
})
})
</script>
</head>
<body>
<div>
<table id="tbl1"
border="1"
cellspacing="1">
<tr>
<td><b>UserName</b></td><td><b>Education</b></td><td><b>Location</b></td>
</tr>
<tr>
<td>Suresh</td><td>B.Tech</td><td>Chennai</td>
</tr>
<tr>
<td>Rohini</td><td>M.Sc</td><td>Chennai</td>
</tr>
<tr>
<td>Mahesh</td><td>Phd</td><td>Delhi</td>
</tr>
<tr>
<td>Madhav</td><td>MBBS</td><td>Nagpur</td>
</tr>
</table>
<table id="tbl2"
border="1"
cellspacing="1">
<tr>
<td>Suresh</td><td>B.Tech</td><td>Chennai</td>
</tr>
<tr>
<td>Rohini</td><td>M.Sc</td><td>Chennai</td>
</tr>
<tr>
<td>Mahesh</td><td>Phd</td><td>Delhi</td>
</tr>
<tr>
<td>Madhav</td><td>MBBS</td><td>Nagpur</td>
</tr>
</table>
<input type="button" id="btnMerge" value="Merge Tables" />
</div>
</body>
</html>
|
Demo
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
1 comments :
Never even thought about doing it with JQuery.. Its blowing my mind right now. Awesome!!!
Note: Only a member of this blog may post a comment.