javascripthtmlbookmarklet

How to click an HTML DOM element through a bookmarklet?


I'm trying to make some bookmarklets to navigate through a web-application.

For some of the links and actions, they're as simple as having bookmarklets such as javascript: tabClick('func');, for others, if I inspect element their href values are void, and I only get these long links.

<a id="id_value" eventvalue="Do Action">Do Action</a>

Is there any way to have a bookmarklet that would simulate clicking Do Action?


Solution

  • Use JavaScript to select the element by its id (unique to that particular element) and send the click event to it, which should emulate exactly the same behavior that would occur if the user were to point and click the element.

    javascript:document.getElementById("id_value").click();