0

Good day,

Im am trying to get only tr's with 7 or more td's on it using a loop.

var table = '<table>';

    $('table tr').each(function() {
        xx = $(this).children().length;
        if(xx>7)
        {
            table += this;
        }
        table+='<table>';
        console.log(xx);
     });

document.getElementById('new_table').innerHTML = table;

but this gives me this result

[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]
[object HTMLTableRowElement]

could anyone please tell me whats wrong please? Thank You verymuch..

melvnberd
  • 3,093
  • 6
  • 32
  • 69
  • hi @chet using this.html I am getting `undefined undefined undefined undefined undefined undefined undefined undefined undefined` – melvnberd Nov 07 '15 at 16:50

2 Answers2

2

You could use Element.outerHTML

table += this.outerHTML;
charlietfl
  • 170,828
  • 13
  • 121
  • 150
0

You can also use:

table += $(this).clone().wrap('<tr></tr>').parent().html();

$(this).html() gives you only the inner html of the element. Here, in your case, you will not get TR but only all TDs inside TR.

Reference: Get selected element's outer HTML

Community
  • 1
  • 1
Ganesh Kumar
  • 3,220
  • 1
  • 19
  • 27