how to merge checked column using js or jquery/

Hi, I created a table with three rows and 4 column and I have a checkbox for each row.
like this
Then if I click the merge button the row which is checked are to be merged

function redclr(){
 	for (var i = 1; i <= 3; i++) 
    	var lfckv = document.getElementById("lifecheck"+i).checked;
    	if (lfckv == true) {
			var tds = document.getElementsByTagName("td");
        	var firstCellId = "";
        	var mergedCells = "";
        for (var i = 0; i < tds.length; i++) {
                mergedCells += tds[i].textContent;
                if (firstCellId == "") {
                    firstCellId = tds[i].id;
                else {
                    tds[i].style.backgroundColor = "gray";
                    tds[i].style.display = "none";
                    tds[i].textContent = "";
        var firstCell = document.getElementById(firstCellId);
        firstCell.textContent = mergedCells; = "gray";

table,tr,td{ border:1px solid;
<table id="demo">

<tr id="row1">
<td id="sel1">a<input type="checkbox" id="lifecheck1"></td>
<td id="sel2">b</td>
<td id="sel3">c</td>

<tr id="row2">
<td id="sel4">d<input type="checkbox" id="lifecheck2"></td>
<td id="sel5">e</td>
<td id="sel6">f</td>


<tr id="row3">
<td id="sel7">g<input type="checkbox" id="lifecheck3"></td>
<td id="sel8">h</td>
<td id="sel9">i</td>


<button type="button" onclick="redclr()">merge</button> 


Open in new window

For example: if I selected 1st and 2nd checkbox then first two row need too merge .
Ajith KumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can you put your code here?
Chris StanyonWebDevCommented:
Your code looks a little confusing so it's not clear exactly what you need merging and where you want the merged results to go. You've tagged this as jQuery, so I'm guessing you want a jQuery solution. Take a look at the following:


<table id="table">
        <td><input type="checkbox"></td>
        <td><input type="checkbox"></td>
        <td><input type="checkbox"></td>

<button id="merge">merge</button>

Open in new window

// jQuery

$(document).ready(function() {
    $('#merge').click(function(e) {
        $('#table tr').each(function(i, row) {
            var text = "";
            if ($(row).find('input').is(":checked")) {
                $(row).css('background-color', 'red');
                $(row).find('td').each(function() {
                    text += $(this).text();
                $('td:first-child', row).text(text);

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
There is no activity from author.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.