A lightweight library for DOM manipulation on modern browser using plain javascript.
Requirements:
- Node.js
- npm (Node.js package manager)
npm install hotdom --save
OR
yarn add hotdom
import dom from 'hotdom'
let el = dom.selectById(id);
dom.getAttributes(el)
selectByClass
const foo = dom.selectByClass('class-name');
addClass()
Add class on element
Takes three arguments, element, class and optional callback
addClass(el, cls, callback)
const heading = dom.selectById('heading');
// add class
dom.addClass(heading, 'common-heading');
findIn()
Find in children elements
Takes three arguments, element, css selector (class, id, tag and so on)
findIn(el, selector)
const main = dom.selectById('main');
// find child element
dom.findIn(main, '.sub-main');
loadScript()
The loadScript()
loads js file dynamically.
It returns promise.
Takes path-of-file
as a argument and loads file dynamically.
Example:
import { loadScript } from 'hotdom'
// replace path with your own
loadScript('https://code.jquery.com/ui/1.12.1/jquery-ui.min.js)
.then(() => {
}).catch(() => console.error('Something went wrong.'));
getUrlParameter()
The getUrlParameter()
returns value of matched key.
Takes key
as a argument and returns value of matched key
Example:
import { getUrlParameter } from 'hotdom'
// https://foo.com/?name=hidy
const params = getUrlParameter('name'); // hidy
Create an issue if you find a bug or have a suggestion or question.
If you want to develop this project:
- Fork it!
- Create your feature branch: git checkout -b my-new-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request