How to merge selected table cells on button click using j query.
- I have created a dynamic table and selecting the table cells using j query. Now i want to merge the selected table cells on button click. How can i do this.
- Thanks, Regards.
- function CreateTable() {
- var rowCtr;
- var cellCtr;
- var rowCnt;
- var cellCnt;
- var myTableDiv = document.getElementById("myDynamicTable");
- var table = document.createElement('Table');
- table.border = '1';
- table.id = 'myTable';
- var tableBody = document.createElement('Tbody');
- table.appendChild(tableBody);
- rowCnt = document.getElementById('txtrows').value;
- cellCnt = document.getElementById('txtcols').value;
- for (var rowCtr = 0; rowCtr < rowCnt; rowCtr++) {
- var tr = document.createElement('tr');
- tableBody.appendChild(tr);
- for (var cellCtr = 0; cellCtr < cellCnt; cellCtr++) {
- var td = document.createElement('td');
- td.width = '120';
- td.appendChild(document.createTextNode("Row:" + rowCtr + " Column:" + cellCtr));
- tr.appendChild(td);
- }
- }
- myTableDiv.appendChild(table);
- $(document).ready(function () {
- $('#myTable td').click(function () {
- var selected = $(this).hasClass('highlited');
- $('#myTable tr').removeClass('highlited');
- if (!selected)
- $(this).addClass('highlited');
- });
- });
- }
-