I need to serialize an entire HTML tag into a string which I selected using the this
keyword in the HTML tag.
Example:
<button id="3" onClick="print(this)">B3</button>
<script type="text/javascript">
function print(element)
{
console.log(element);
var x = element.toString()
console.log(x)
}
</script>
When we check the first console.log
statement, the result will be:
<button id="3" onClick="print(this)">B3</button>
In the second console.log
statement, the result will be:
[object HTMLButtonElement]
Is there any way I can serialize the tag into string like:
"<button id="3" onClick="print(this)">B3</button>"