Event element selectors
This article describes the element selectors used with event listeners.
Most event listeners require that you specify which element on a page you want trigger the event listener. For example, configuring a click event to track when a visitor clicks on a specific ad banner or button, or when a visitor plays a specific embedded video.
Specify the element to track by element ID, class, or a complex selector.
Selector type | Example | Description |
---|---|---|
Element ID | #email-address |
A form field to collect email address |
Class | .form-field |
Any form field |
Complex selector | div#feedback-form:not(.main) input[name='email'] |
A form field named email in a div with ID feedback-form , but not within a div with class main . |
The event system uses the Element.matches()
method for the selector. For more information about this method, see Element.matches() at Mozilla Developer Network.
For more information about how to determine an element’s selector, see How to Determine the CSS Selector of an Element.
This page was last updated: June 30, 2023