javascriptgoogle-chromeclicklistener

Manually trigger event listener from Chrome console


I don't know much about Javascript but I though the .click command was the way to simulate a click on an item, let's say with something like

document.getElementById('id').click

I recently found a webpage where the buttons .click command did not triggered anything though my actual real clicks do.

I dug a bit and found that there are no event on the onclick of those buttons though they seem to have some eventlistener attached.

Hence I am looking to the proper command out of my Chrome console to trigger the event without actually clicking. Anyone can help on this?

Regards


Solution

  • Ok that was a very stupid question from me thanks to my lack of knowledge of javascript (and tiredness maybe regarding how easy the answer is).

    So I just lacked a few parenthesis in my click command...

    (EDIT: fixed typo in method)

    document.getElementById('id').click()
    

    And now it's fine... sorry for bothering you and thanks to @Kasabucki Alexandr who indirectly showed me the correct answer