Introduction:
In this article, I will explain how to use jQuery or javascript to merge multiple tables into a single table.
Implementation:
To merge two tables into single table we need to write the
code like as shown below :
<script type="text/javascript">
$(function () {
$('#btnMerge').click(function () {
$('#tbl1
> tbody:last').append($('#tbl2 > tbody').html());
$('#tbl2').remove();
})
})
</script>
Source Code for Sample Application:
<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>EmpName</b></td><td><b>Education</b></td><td><b>Designation</b></td>
</tr>
<tr>
<td>Anil</td><td>B.Tech</td><td>Software
developer</td>
</tr>
<tr>
<td>Anish</td><td>M.Sc</td><td>Trainer</td>
</tr>
<tr>
<td>Anuj</td><td>Phd</td><td>Professer</td>
</tr>
<tr>
<td>Ankit</td><td>MBBS</td><td>Doctor</td>
</tr>
</table>
<table id="tbl2" border="1" cellspacing="1">
<tr>
<td>Akshay</td><td>B.Tech</td><td>Developer</td>
</tr>
<tr>
<td>Ankush</td><td>M.Sc</td><td>Trainer</td>
</tr>
<tr>
<td>Ajay</td><td>Phd</td><td>Professer</td>
</tr>
<tr>
<td>Ashish</td><td>MBBS</td><td>Doctor</td>
</tr>
</table>
<input type="button" id="btnMerge" value="Merge Tables" />
</div>
</body>
</html>
0 comments:
Post a Comment