cssSelectorExample

Simple example of using css-selector

HTML

<script src="//rawgit.com/afloesch/css-selector/master/index.js"></script>
<div class="some-content">
  <div>
    <input type="text" class="username" />
    <input type="password" />
    <p></p>
  </div>
  <div>
    <button>A button</button>
  </div>
  <div>
    <div></div>
    <div>
      <p>
        Some text content here
      </p>
    </div>
  </div>
  <hr />
</div>

CSS

div {
  margin: 10px;
}

JavaScript

// the catchSingleEvent method is a helper method provided
document.body.catchSingleEvent('click', function(e) {

  if (!e.isTrusted) return;
  
  // this is the meat of it right here
  var selectors = e.target.getSelectors();

	var txt = document.createElement("div");
  txt.innerHTML = selectors;
  document.body.appendChild(txt);
});