Giter Site home page Giter Site logo

unique-selector's Introduction

unique-selector

Build Status CocoaPods semantic-versioning

Given a DOM node, return a unique CSS selector matching only that element. This is particularly useful when tracking in custom variables in analytics:

document.addEventListener('click', function(event) {
    var selector = unique(event.target);

    _gaq.push(['_trackEvent', 'Engagement', 'Click', selector]);
}, false);

Installation

NPM

Options

e.g.1 DomElement = <span id="test"></span>

import unique from 'unique-selector';

// Optional Options
options = {
    // Array of selector types based on which the unique selector will generate
    selectorTypes : [ 'ID', 'Class', 'Tag', 'NthChild' ]
}

unique( DomElement, options ); // #test

e.g.2 DomElement = <span test="2"></span>

import unique from 'unique-selector';

// Optional Options
options = {
    // Array of selector types based on which the unique selector will be generate
    selectorTypes : [ 'Attributes' ]
}

unique( DomElement, options ); // [test="2"]

e.g.3 DomElement = <div id="xyz" class="abc test"></div>

import unique from 'unique-selector';

// Optional Options
options = {
    // Regular expression of ID and class names to ignore
    excludeRegex : RegExp( 'xyz|abc' )
}

unique( DomElement, options ); // .test

Tests

$ npm run test

Contributing

Feel free to open issues, make suggestions or send PRs. This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code.

Contact

Avraam Mavridis : @avraamakis

Eric Clemmons : @ericclemmons

Releases

  • v0.1.0

    • Big refactor/rewrite using es6
    • More test + Change the test script
    • Script to compile es6 to es5 using babel
    • Ability to pass options for the selectorTypes based on which the unique selector will be generated, see the options
  • v0.0.4

    • Handle extra whitespace in className (#9)
  • v0.0.3

    • Add support for various <form> elements (#2)
  • v0.0.2

    • Fix bug with nth-child calculation
  • v0.0.1

    • Initial release

License

MIT

Bitdeli Badge

unique-selector's People

Contributors

avraammavridis avatar ericclemmons avatar vwochnik avatar joshwnj avatar bertyhell avatar bitdeli-chef avatar carloslancha avatar g0dwin avatar jeetiss avatar jkroso avatar osnysantos avatar patmood avatar ronkorving avatar frakti avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.