Click events, they don't work at first click

so wether i use adeventlistener(‘click’, … or put onclick inside the div tag, i always have to click it twice so the function could execute.
why is that and how to fix it? any alternatives?
thank you.

We can’t help you unless you post what you have tried so far.

the code is about more than 10000 lines.
let me build a little demo example , and get back at you.

i solved it by reversing some code, thank you.
i always ask a question here on forum, and then ding ding ding, i get it in my head.