0

How can i simulate a click in this element?

<a href="javascript:;" onclick="ExecutarLance('59272');" title="ExecutarLance" class="btn btn-custom3">LANCE</a>

Normally I simulate clicks using the id (document.getElementById("id"); or the class, but this element does not have an id and the class indicated is the same for several elements on the page.

In this case, this element is a button and the only specific attribute of it is the onclick.

I just want to simulate the click on this button.

Is it possible to simulate the click using the onclick as a reference?

  • 1
    Not tested but `document.querySelector("a[onclick=\"ExecutarLance('59272');\"]")`? – kelsny Nov 09 '22 at 21:21
  • 1
    You can trigger clicks on elements selected by _any_ means--relative position, attribute value, etc. You might ask why you're doing that, though. The right approach is generally not to trigger clicks but to call functions directly. – isherwood Nov 09 '22 at 21:22
  • @caTS, use single quotes in your JavaScript and you won't need awkward backslash escaping. – isherwood Nov 09 '22 at 21:23
  • 1
    Does this answer your question? [How can I find an element by onclick attribute value?](https://stackoverflow.com/q/22237383/1264804) – isherwood Nov 09 '22 at 21:25

0 Answers0