click() firing multiple times

前端 未结 3 1400
心在旅途
心在旅途 2021-01-21 09:21

I am using a document.getElementById(\"val\").click() to invoke a click event, but it keeps firing multiple times.

Here I add the eventHandler:



        
3条回答
  •  遇见更好的自我
    2021-01-21 09:54

    Usually when you have an event firing multiple times it is because the event is attached to an element more than once or the element you are auto clicking is a child of another element with the same event attached. Check to see if they are wrapped by each other and if so you will need to detect that the current target is equal to the target to make sure it only happens once. Or you can stop the event propagation.

提交回复
热议问题