click() now works on elements outside of document

Published:

Categories: DOM

Releases: Firefox 75, Firefox 78 ESR

Description

Previously, Firefox had discarded the HTMLElement.click method triggered on an element that wasn’t part of a document. On Firefox 74 and later, such method calls will work and the corresponding click event will be fired on that element. Since the new behaviour mostly aligns with other browsers, it’s unlikely to cause site compatibility issues. However, if a site is using a user-agent sniffing to run code specific to Firefox that assumes the click event will not be fired, this change could be a potential problem.

const $input = document.createElement('input');
// This `click` event will be logged from now on
$input.addEventListener('click', event => console.log(event));
// Here the `<input>` is not yet added to the `document`
$input.click();

References