I am new in Prototype js. I have an element like this,
<li id="toolbar-save" class="button">
<a class="toolbar" href="www.mydomain.com/register">
Save & Close
</a>
</li>
I have a selector for the anchor tag, $$('#toolbar-save a')
.
By using this selector how can I trigger the click event ?
or any other way you can suggest ?
thanks in advance.
The HTMLElement. click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.
If you want native JS to trigger click event without clicking then use the element id and click() method of JavaScript.
If click on the link while in GTM preview mode and check out the Click Element in the preview console, you'll notice that it is listed as an object in the Data Layer. Since it's a Data Layer object, we can dig a little deeper in the element using our Developer Tools to find a CSS selector.
You can use the matches CSS selector trigger predicate together with the Click Element variable to check if the element matches a specific selector (d'oh).
$$('#toolbar-save a')[0].click();
FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With