npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

phane-tech-dom-utils

v1.0.3

Published

Pure JavaScript DOM utility functions

Readme

📦 Kotipalli Phaneendra Kumar - Array Utilities

A lightweight, safe, and predictable DOM utility module that simplifies common DOM operations with strict validation, consistent return values, and clean JSDoc documentation.

Designed specifically for browser environments, this module helps you work confidently with elements, attributes, classes, styles, events, and dynamic DOM creation without unexpected runtime errors.


✨ Highlights

  • 🧱 Safe DOM selectors with validation
  • 🏷️ Attribute helpers (get / set / remove)
  • 🧩 Class utilities (add / remove / toggle / check)
  • 🎨 Style helpers (single & multiple styles)
  • 🧩 Dynamic element creation & DOM insertion
  • 🎧 Event listener helpers
  • ⭐ Tab title & favicon utilities
  • 📚 Fully documented using JSDoc
  • ⚡ Predictable return values (undefined for invalid input)

📦 Installation

npm install phane-js-dom-helpers

🚀 Import

import {
  getElementById,
  getElementsByClassName,
  getElementsByTagName,
  setTabTitle,
  getTabTitle,
  setFavicon,
  getFavicon,
  setTextContent,
  setHTMLContent,
  setAttribute,
  getAttribute,
  removeAttribute,
  hasClass,
  addClass,
  removeClass,
  toggleClass,
  setStyle,
  setStyles,
  createDynamicElement,
  appendDynamicTag,
  removeElement,
  addEventListenerHelper,
  removeEventListenerHelper,
  onElementLoad,
  setDataId
} from "phane-js-dom-helpers";

📚 API Reference

🔍 getElementById(id)

Safely returns a DOM element by its ID.

getElementById("header"); // HTMLElement | null
getElementById("unknown"); // null
getElementById(""); // undefined

🔍 getElementsByClassName(className)

Returns a live HTMLCollection of elements.

getElementsByClassName("card"); // HTMLCollection

🔍 getElementsByTagName(tagName)

Returns a live HTMLCollection of elements.

getElementsByTagName("div"); // HTMLCollection

🏷️ setTabTitle(title)

Sets the browser tab title.

setTabTitle("Home"); // "Home"

⭐ getTabTitle()

Returns the current tab title.

getTabTitle(); // "Home"

⭐ setFavicon(url)

Sets or updates the browser favicon.

setFavicon("/favicon.ico");

⭐ getFavicon()

Returns the current favicon URL if available.

getFavicon(); // string | undefined

✏️ setTextContent(element, text)

Safely sets innerText on an element.

setTextContent(el, "Hello World");

✏️ setHTMLContent(element, html)

Safely sets innerHTML on an element.

setHTMLContent(el, "<b>Hello</b>");

🧱 setAttribute(element, name, value)

Adds or updates an attribute.

setAttribute(el, "data-id", "123");

🧱 getAttribute(element, name)

Gets an attribute value.

getAttribute(el, "data-id"); // "123"

🧱 removeAttribute(element, name)

Removes an attribute.

removeAttribute(el, "disabled");

🧩 hasClass(element, className)

Checks if a class exists on an element.

hasClass(el, "active"); // true | false

🧩 addClass / removeClass / toggleClass

Manages element classes safely.

addClass(el, "active");
removeClass(el, "active");
toggleClass(el, "active");

🎨 setStyle(element, property, value)

Sets a single CSS style.

setStyle(el, "color", "red");

🎨 setStyles(element, styles)

Applies multiple CSS styles at once.

setStyles(el, {
  color: "red",
  backgroundColor: "yellow"
});

🧩 createDynamicElement(tag, content?, props?)

Creates a DOM element dynamically.

createDynamicElement("div", "Hello", {
  id: "box",
  className: "card"
});

➕ appendDynamicTag(child, parent?)

Appends an element to the DOM.

appendDynamicTag(div);
appendDynamicTag(div, container);

❌ removeElement(child, parent?)

Removes an element from the DOM.

removeElement(div);

🎧 addEventListenerHelper(el, type, handler)

Adds an event listener safely.

addEventListenerHelper(btn, "click", handleClick);

🎧 removeEventListenerHelper(el, type, handler)

Removes an event listener safely.

removeEventListenerHelper(btn, "click", handleClick);

⏳ onElementLoad(element?, handler)

Executes a handler when DOM or element is ready.

onElementLoad(null, () => console.log("DOM Ready"));

🆔 setDataId(element, value)

Sets data-id attribute.

setDataId(el, "123");

🧪 Design Principles

  • ❌ Invalid input → undefined
  • ✅ Safe DOM access
  • 🔁 No unexpected mutations
  • 📖 Predictable, documented behavior

📄 License

MIT


🔗 Links

  • GitHub Repository: https://github.com/phane-tech/phane-tech-dom-utilities
  • Demo / Documentation: https://phane-tech.github.io/phane-tech-dom-utilities/module-DomHelpers.html
  • Unit Test Cases Reports: https://phane-tech.github.io/phane-tech-dom-utilities/unit-test-report.html