aboutsummaryrefslogtreecommitdiffstats
path: root/root/sandbox/javascript/text$javascript -> mmm$dom.js
blob: 58deb23f85c951a5fe7f68fe3b8a054c6555f052 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// a little helper function for creating DOM elements
const e = (elem, children) => {
  const node = document.createElement(elem);

  if (typeof children === 'string')
    node.innerText = children;
  else
    children.forEach(child => node.appendChild(child));

  return node;
};

/* creating the equivalent of the following HTML directly as DOM content:
 *
 * <article>
 *   <h1>JavaScript</h1>
 *   <p>...</p>
 * </article>
 */

return e('article', [
  e('h1', 'JavaScript'),
  e('p', 'JavaScript is supported natively in the browser but is not currently pre-rendered on the server.'),
]);