element-content-hash

Generate a unique hash based on the contents of a DOM element

Stats

StarsIssuesVersionUpdatedCreatedSize
element-content-hash
001.1.13 years ago3 years agoMinified + gzip package size for element-content-hash in KB

Readme

element-content-hash

element-content-hash is a library for generating a unique identifier for an element, based on its contents.

Usage

import elementContentHash from "element-content-hash";

// Based on an existing element in the DOM
const h1 = document.body.querySelector("h1");
elementContentHash(h1); // => '123456789'

// Or based on an element you create
const div = document.createElement("div");
div.appendChild(document.createTextNode("hello, world"));
elementContentHash(div); // => '1634983957'

Implementation

element-content-hash strips out any HTML attributes when computing the content hash (to avoid changing attributes appended by libaries like Vue.js). If you are passing:

  • An img: only the src will be hashed
  • Any other element: the outerHTML of the element will be used, the attributes will be stripped, and the remaining content hashed.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.