@makecode/dom-manager
A lightweight JavaScript library for DOM manipulation inspired by jQuery. It provides an easy and flexible API to interact with and modify DOM elements.
Installation
Install the package via npm:
npm install @makecode/dom-manager
Usage
Import the library and use it in your project:
import $ from '@makecode/dom-manager';
const dom = $('body');
console.log(dom.isVisible());
dom.addClass('new-class');
console.log(dom.getClass());
dom.toggleClass('new-class');
console.log(dom.getClass());
dom.data({ 'test-attr': 'value' });
console.log(dom.data('test-attr'));
const newDiv = $('<div>').attr({ id: 'new-div', class: 'example-class' });
dom.append(newDiv);
console.log($('body').contains(newDiv));
Features
- Attribute manipulation (
attr, removeAttr, hasAttr)
- Class manipulation (
addClass, removeClass, toggleClass, hasClass)
- Style manipulation (
css)
- Element visibility (
isVisible)
- DOM traversal (
next, prev, closest)
- Element insertion and replacement (
prepend, append, before, after, replaceWith)
- Data attributes (
data)
- Scroll parent detection (
scrollParent)
- Node comparison (
isEqualNode)
Browser Compatibility
- Modern browsers: Chrome, Edge, Firefox, Safari
- Internet Explorer: IE11+
This library relies on modern JavaScript APIs such as dataset, classList, and matches, so ensure your environment supports these features or includes polyfills for older browsers.
License
MIT