Skip to content

Getting started

David Ortner edited this page May 23, 2023 · 16 revisions

Installation

npm install happy-dom

Usage

A simple example of how you can use Happy DOM.

import { Window } from 'happy-dom';

const window = new Window({
   url: 'https://localhost:8080',
   width: 1024,
   height: 768
});
const document = window.document;

document.body.innerHTML = '<div class="container"></div>';

const container = document.querySelector('.container');
const button = document.createElement('button');

container.appendChild(button);

// Outputs "<div class="container"><button></button></div>"
console.log(document.body.innerHTML);
Clone this wiki locally