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

html-element-picker

v1.1.2

Published

Pick and highlight any HTML Element on a page using only Vanilla JS (highly configurable)

Downloads

47

Readme

html-element-picker

Pick and highlight any HTML element on a page using only Vanilla JS. Hovered elements are automatically highlighted in the color you want. Tested in Chrome, Firefox, and Opera, does not work in IE.

Installation

NPM

npm install html-element-picker

CDN

Append the one of the following scripts at the end of body tag

jsDelivr

<script src="https://cdn.jsdelivr.net/npm/html-element-picker@latest"></script>

Unpkg

<script src="https://unpkg.com/html-element-picker@latest"></script>

Update

Because of the usual 24-hour cache by CDN providers, you should replace the @latest tag with @(the latest version number) for immediate update to the latest version. It's always the safest to use the current stable version @1.0.4.

Support

See the html-element-picker API documentation.

Usage

After importing html-element-picker, instantiate the ElementPicker class with optional configurations.

new ElementPicker(options);

The default configurations are

{
container: document.body,
selectors: "*",
background: "rgba(153, 235, 255, 0.5)",
borderWidth: 5,
transition: "all 150ms ease",
ignoreElements: [document.body],
action: {}
}

container (HTMLElement)

container is the boundary of the element picker. No highlights will be shown on mouse hover outside the container. Defaults to the document body.

selectors (String)

selectors serve as the filter for the element picker. Only elements matching the CSS rule specified in the selectors string will be highlighted. Defaults to accepting all elements ("*", star operator).

background (String)

background specifies the background color of the higlight when an element is hovered. You should always set a transparent color using "rgba(...)" or "hsla(...)" so as not to block the hovered element. Same as setting elementPicker.hoverBox.style.background. Defaults to light blue.

borderWidth (Integer)

borderWidth indicates the width of the highlight box border (in px) that covers the hovered element. Pass in a positive value to enlarge the highlight box and a negative to decrease the size (smaller than the hovered element). Zero means no border or same size as the hovered element. Defaults to 5px.

transition (String)

transition specifies the animation when the highlight box transfer to another hovered element. Same as setting elementPicker.hoverBox.style.transition. Pass in "" (empty string) to disable transition. Defaults to "all 150ms ease".

ignoreElements (Array of HTMLElement)

ignoreElements lists the elements to not highlight when being hovered over. Add, remove, modify elements in this property same as a normal array (push, pop, etc). The order of elements does not matter. Defaults to the document body.

action (Object with two properties)

action indicates a callback function to run when an event is triggered and the target element is being picked up by the element picker, meaning only elements that are accepted by the picker will trigger the callback. trigger is a String with possible event names such as "click", "dblclick", "mouseover", etc. callback is a function given a target parameter when triggered which contains the hovered element. Sample callback functions are:

(function (target) {
    target.remove();
})
(function (target) {
    target.style.fontSize = "50px"; 
})
(function (target) {
    target.classList.toggle("highlight");
})

A full action option can look like:

action: {
    trigger: "click",
    callback: (function (target) {
        target.classList.toggle("highlight");
    })
}

You must surround the callback function with parentheses just like Immediately Invoked Function Expressions (IIFEs). Defaults to no action (empty Object).

Dynamic Update

All of the above options can be dynamically updated in Javascript at runtime. Element picker will respond immediately to any configuration change.

License

This project is licensed under the terms of the MIT license.