2.0.3 • Published 6 months ago

vanillajs-browser-helpers v2.0.3

Weekly downloads
79
License
MIT
Repository
-
Last release
6 months ago

Vanilla JS Browser helpers

This is a collection of simple, no dependency, vanilla JS snippets with the aim of making it easier to work with vanilla JS.

They is written in ES6, since most of the major browsers support this syntax, all scripts have however been converted into the Echma Script 5 syntax (without polyfills) and stored in the ./es5 folder if needed.

Polyfills haven't been included as they exist in abundance on NPM, and since the need for polyfills are ever diminishing it is more future proof and clutter free to leave them out.

GENERAL HELPERS

These helpers are browser specific, for more general helpers check out: vanillajs-helpers

Documentation

Documentation is written in the Wiki of the GitHub repository, but here below is an overview of the helpers available.

Helpers

MethodDescription
addClassAdd class to a DOM element
afterInsert HTML or ad DOM element after a DOM element
appendInsert HTML or ad DOM element into the end of a DOM element child list
attrGet/set an attribute of a DOM element
beforeInsert HTML or ad DOM element before a DOM element
childrenGet the direct child DOM elements of a DOM element
createCreates DOM element from CSS selector
cssGet/set styling of a DOM element
createCreates a DOM element from a selector (eg. div#myDiv.some-class)
dataGet/set value of a data attribute on a DOM element
delegateBind delegate event(s) to a DOM element
domReadyBind a handler to the document ready event
elmIndexGet the index of a DOM node amongst its siblings
eventPlusSophisticated on/off event bindings:- Remove all events- Event name spacing- Delegates
findFind method that detect the most efficient find method depending on the query. Also includes certain wildcards.
findByClassFind DOM elements by class name
findByIdFind DOM element by ID
findByNameFind DOM elements by name attribute
findByQueryFind DOM elements using CSS query
findByTagNameFind DOM elements by tag name
hasClassDetect if a DOM element has a given class
hiddenDetect if a DOM element is hidden or not
inDOMDetect if a DOM element is inserted into the DOM
inViewDetect if a DOM element is in view on the screen
invisibleDetect if a DOM element is invisible or not
isDOMChildNodeDetect if a DOM element is a child node of another DOM element
isDOMContainerDetect if a DOM node is a can contain child nodes
isDocumentDetect if a DOM node is the document node
isDOMElementDetect if a DOM node is a DOM element
isDOMFragmentDetect if an object is a document fragment
isDOMNodeDetect if a DOM node is actually a DOM node
isDOMRootDetect if a DOM node is the root element (body in HTML)
isWindowDetect if an Object is a window object
matchesDetect if a DOM node match a given CSS selector
offRemove event handler from a DOM element
onAdd event handler to a DOM element
onceAdd a single fire event handler to a DOM element
positionGet the position of a DOM element
prefixedPrefixes a name with vendor prefixes (webkit, moz, ms, o)
prependInsert HTML or ad DOM element into the beginning of a DOM element child list
removeRemove a given DOM element from the DOM
removeClassRemove a given class name from a DOM element
replaceReplace a given DOM element with another
scrollByScroll page or given DOM element by x number of pixels left/right
scrollInfoGet information about current window or DOM element scroll positions (includes percentage scrolled)
scrollParentGet the current DOM elements scrolling parent
scrollToScroll page or given DOM element to given x and y coordinate
siblingsGet the siblings of a DOM element
sizeGet the size of a DOM element
supportsCSSDetects whether the current browser supports a given CSS prop and/or value
toDOMConvert a HTML string into DOM element(s)
toggleClassToggle a class from a DOM element
triggerTrigger an event handler on a DOM element
viewportGet the current viewport area
visibleDetect if a DOM element is visible or not

Installation

npm install vanillajs-browser-helpers

Usage

// ES 6
import append from 'vanillajs-browser-helpers/append';
append('<div class="child-element"></div>');
// ES 5
var append = require('vanillajs-browser-helpers/es5/append').default;
append('<div class="child-element"></div>');

Something missing?

If you find any bugs or missing functionality you would like to see included, feel free to add an issue in the issue list or perhaps do a Pull Request of a great snippet you created.

Testing

Check out the Testing docs

2.0.3

6 months ago

2.0.2

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago