DevTools Tips

Copy an element's JavaScript path

Categories: Supported by:

JavaScript often needs references to DOM nodes on the page. Getting a reference is sometimes easy with document.getElementById() or similar. Other times however, a more complicated CSS selector needs to be created and used with document.querySelector().

To automatically get the right JavaScript expression to use for any node:

  1. Find the node you are interested in in the Elements tool.
  2. Right-click the node and select Copy > Copy JS path.
  3. The right document.querySelector() expression is now in your clipboard. You can paste it anywhere you need it.

Screenshot of the Elements tool in Edge showing the context menu on an element, with the Copy JS path option