a recommendation from creator ("discoverer") of JSON, Douglas Crocford
Plain Old JavaScript and the DOM
The DOM is much less deficient and much more portable and reliable. That is why I now recommend abandoning the libraries, which have grown into bloated platforms, and instead using the DOM and plain old JavaScript together.function dom(tag, ...nodes) {
const node = document.createElement(tag);
node.append(...nodes);
return node;
}
let rows = [
dom(
"tr",
dom("th", "first"),
dom("th", "last")
),
dom(
"tr",
dom("td", "Moe"),
dom("td", "Howard")
),
dom(
"tr",
dom(
"td",
"Jerome",
dom("i", "Curly")
),
dom("td", "Howard")
),
dom(
"tr",
dom("td", "Larry"),
dom("td", "Fine")
)
];
document.getElementById("output").append(dom(
"table",
dom("caption", "The Three Stooges"),
...rows
));
No comments:
Post a Comment