Skip to content

Get unique dom element path for specified element.

License

Notifications You must be signed in to change notification settings

aidenybai/dom-element-path

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lint

dom-element-path

Get unique dom element path for specified element.

Installation

npm:

npm install dom-element-path

yarn:

yarn add dom-element-path

Usage

import domElementPath from 'dom-element-path';

const body = domElementPath(document.body);
console.log(body);

Output:

html > body

One of the common use cases is where you have event in some sort of event handler and want to get path of element that the event was fired off:

import domElementPath from 'dom-element-path';

const onClick = event => {
    const clickedElementPath = domElementPath(event.target);
    console.log(clickedElementPath);
};

Output:

html > header > div.header-menu > ul > li:nth-of-type(4) > a.login-button

Development

run linter:

yarn lint

run tests:

yarn test

create build:

yarn build

About

Get unique dom element path for specified element.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%