by Before Semicolon

Element

Element details
Details
name Element
type class
arguments tag name
properties most DOM Element properties
methods most DOM Element properties
description A class representing DOM document Element.

Constructor

The constructor takes a required absolute path to the file and an optional source directory.

Properties and Methods

The element instance is a server-side replica of the browser Element node. It shares the node most properties and methods.

Note: As of now, most Element properties and methods are available, except for a few like the query selectors, style, classList, and dataset. It also does not contain any Event related or other properties and methods that only make sense on the client.

Context

You can set context on the element which is a feature unique to HTML+ which allows you to define the data the element can refer to for rendering.

const path = require("path");
const {Element} = require("@beforesemicolon/html-plus");

const title = new Element('h2');
title.setAttribute('id', 'main-title');
title.textContent = '{title}';
title.setContext('title', 'Main Title');

// when rendered it will become
// <h2 id="main-title">Main Title</h2>