New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

domdon

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

domdon

Syntax sugar for querySelector / querySelectorAll

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
7
250%
Maintainers
1
Weekly downloads
 
Created
Source

Simple DOM Selection

Domdon builds on top of document.querySelectorAll() adding a small ammount of syntax sugar, to make your code a little cleaner and easier to read.

The most basic use is very similar to how querySelector or querySelectorAll work.

<div id="countries">  
  <ul>  
    <li>Germany</li>  
    <li>Belize</li>  
    <li>France</li>  
    <li>Australia</li>  
    <li>India</li>  
  </ul>  
</div>  

Against this html running:

DOM('#countries')

Would return the countries div.

If there is only one element then DOM() will return that Node, if there is more than one element then DOM() will return an array of all the elements.

DOM('li')

Would return an Array (not a NodeList) containing all of the li elements.

This makes it very easy to write stuff like this:

DOM('li').forEach(li => li.style.color = 'red')

I have found this method to work really well as generally I tend to know the structure of the html. If for any reason you are not sure what will come back, then you can always use DOM.array() to make sure an array is returned.

DOM.array('#countries').forEach(el => el.innerHTML = '')

This will return an array no matter what, so even if nothing is found for that selector you can still run .filter .forEach .reduce on the results.

var activeNoop = DOM.array('.noop').filter(el => el.classList.contains('active'));

This code will run without error, and activeNoop will be undefined;

Keywords

dom

FAQs

Package last updated on 04 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts