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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xassist/xassist-dom

v1.0.2

Published

Basic helperfunctions for DOM-elements

Downloads

18

Readme

@xassist/xassist-dom

Basic helperfunctions for DOM-elements

Installation

If you use NPM, you can install the module via npm install xassist-dom. Otherwise, you can download the latest minified file. Be aware any dependencies are not installed by default; you should consider downloading them yourself. If you want, you can install the complete library from github xassist, this includes all dependencies you may need.

The module uses UMD and supports AMD, CommonJS and vanilla environments. Using vanilla: the xaglobal is exported:

<script>
xa.dom()
</script>

API

dom()

The base function object() creates a new Class instance which gives access to some helper Object-functions

dom(/*element::HTMLElement*/)

note that the new- keyword should not be used to create the class-instance.

Parameters for dom()

dom() takes 1 parameters:

  • element [HTMLElement]:an Element on which we will execute the underlying methods

Result for dom()

dom() returns a new class instance of the Class XaDOMelement

dom(a).constructor.name==="XaDOMelement"

XaDOMelement returns 9 method:

  • addClass(): adds a classname to the current element
  • removeClass(): removes a classname from the current element
  • hasClass(): checks if the element has a specified classname
  • replaceClass(): replaces a certain class with another
  • toggleClass(): toggle the specified classname
  • attr(): sets an attribute to a certain value
  • parents(): returns all parents of specified element
  • isVisible(): checks if the current element is visible
  • getDimensions(): gets the dimensions of the element, evne when it's hidden

XaDOMelement has 1 own attributes:

  • e[HTMLElement]:the current base DOM element, provided via the simple factory-function dom()

Example for dom()

dom(document.getElementById('test'))

dom().addClass()

adds a classname to the current element

dom(elm).addClass(className::String)

Parameters for dom().addClass()

dom().addClass() takes 1 parameters:

  • className [String]:the name of the class we are looking for

Result for dom().addClass()

this method returns the original XaDOMElement, so it can be used for method-chaining

dom().removeClass()

removes a classname from the current element

dom(elm).removeClass(className::String)

Parameters for dom().removeClass()

dom().removeClass() takes 1 parameters:

  • className [String]:the name of the class we are looking for

Result for dom().removeClass()

this method returns the original XaDOMElement, so it can be used for method-chaining

dom().hasClass()

checks if the element has a specified classname

dom(elm).hasClass(className::String)

Parameters for dom().hasClass()

dom().hasClass() takes 1 parameters:

  • className [String]:the name of the class we are looking for

Result for dom().hasClass()

this method returns a Boolean indicating if the class exists on the current element

dom().replaceClass()

replaces a certain class with another

dom(elm).replaceClass(className::String,newClassName::String)

Parameters for dom().replaceClass()

dom().replaceClass() takes 1 parameters:

  • className [String]:the name of the class we are looking for

Result for dom().replaceClass()

this method returns the original XaDOMElement, so it can be used for method-chaining

dom().toggleClass()

toggle the specified classname

dom(elm).toggleClass(className::String [,toggle::Boolean])

Parameters for dom().toggleClass()

dom().toggleClass() takes 2 parameters:

  • className [String]:the name of the class we are looking for
  • toggle [Boolean,defaults to: !this.hasClass(className)]:a boolean indicating if we should add(true) or remove (false) the className

Result for dom().toggleClass()

this method returns the original XaDOMElement, so it can be used for method-chaining

dom().attr()

sets an attribute to a certain value

dom(elm).attr(attrName::String,value)

Parameters for dom().attr()

dom().attr() takes 2 parameters:

  • attrName [any datatype]:the name of the attribute we want to set
  • value [any datatype]:the value of the attribute we need.

Result for dom().attr()

this method returns the original XaDOMElement, so it can be used for method-chaining

dom().parents()

returns all parents of specified element

dom(elm).parents()

dom().parents() requires no parameters.

Result for dom().parents()

this method returns an Array with all parents of the current element

dom().isVisible()

checks if the current element is visible

dom(elm).isVisible()

dom().isVisible() requires no parameters.

Result for dom().isVisible()

this method returns a Boolean indicating the visibility of the element

dom().getDimensions()

gets the dimensions of the element, evne when it's hidden

dom(elm).getDimensions()

dom().getDimensions() requires no parameters.

Result for dom().getDimensions()

this method returns BoundingClientRect-object

DevDependencies

  • csv2readme: read csv file with fixed format and parse a readme markdown file
  • jsdom: A JavaScript implementation of many web standards
  • rimraf: A deep deletion module for node (like rm -rf)
  • rollup: Next-generation ES6 module bundler
  • tape: tap-producing test harness for node and browsers

License

This module is licensed under the terms of GPL-3.0.