Search code examples
javascripthtmlonclickevent-listener

Button doesn't have obvious onclick event


I'm looking at elements which don't seem to have an onclick event registered. Inspecting the DOM I can't find any yet the event fires when you click on it.

An example is Linktree profiles like this one which have buttons that when you click on them the link is constructed and it opens it but the elements don't look like they specify it in any obvious way.

I thought there may be some global event listener for button elements but the elements appear to be generic with no "id" identifier so I can't see how they are linked.

Do these use some method I don't know about or is it some hack?

EDIT: My question doesn't have other answers. The event listener part has been answered but my question is mainly about the link between the element and the action it performs which is not apparent.


Solution

  • So far I see the button you mentioned definitely has the click listener. Click event listener evidence

    Unfortunately the source code is minified so I can't say detailed what exactly it does but I do believe that it definitely might have one of the following options to show the block below.

    1. in case of vanilla it might be just on the fly elements creation and inserting them into the DOM and might use some selectors to find the and insert the element there. anchor element
    2. it might use any UI lib/framework to get the ref to the element by the lib methods like React refs and it could manipulate the real dom by virtoual dom with the conditional rendering

    anyway, it doesn't matter what exactly the techical implementation of the conditional UI rendering they have used but they definitely use click event listener so maybe, just try to inspect the DOM carefully. The possibility for the global event is real but I really don't believe that someone would do it except some experimental purpose :) but even in this case the Chrome inspector in the Event listeners tab will show it.