Create a new table with rows of only checked checkboxes

Create a new table with rows of only checked checkboxes

Hello!

I have an HTML table with a checkbox in each row. I want to loop over the table and if there are any checkboxes that are checked. I need to create a new table with rows of only checked checkboxes.

Any advice will be appreciated! I know how to go through the table. But how to store HTML code of that row in the variable?

What I am trying to do is to send new table to a new page.

 function toView(){ var newWindow = window.open(); var newHTML = '<html><head></head><body><table>'; var endHtml = '</table></body></html>'; $('table tbody tr').each(function() { var $tr = $(this); if ($tr.find('input[type="checkbox"]').is(':checked')) { // what suppose to be here.... } }); newHTML = new_table + endHtml newWindow.document.write(newHTML); }