JSFiddle - React, Tailwind, and code Playground
by brigand
HTML
<form action="salkdj" data-foo="bar">
<h2>form</h2>
<input type="text">
<input type="text">
</form>
<div id="out"></div>
JavaScript
const form = document.querySelector('form');
let s = '<' + escapeHtml(form.tagName.toLowerCase())
for (const {
name,
value
} of form.attributes) {
s += ' ' + escapeHtml(name) + '="' + escapeHtml(value) + '"'
}
s += '>';
out.textContent = s
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}