I have a table and I would like to assign the HTML as a string variable. How can I do it so that the opening/closing table
tags are included in the string? I know I could just wrap the table in a container and get the HTML of the container, but wondering if there's a solution without modifying the layout.
$(function() {
// want the following variable to include open/closing table tags
var tableHTML = $('table').html();
alert(tableHTML);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>