How to trigger event in JavaScript?

前端 未结 18 1902
情深已故
情深已故 2020-11-21 04:48

I have attached an event to a text box using addEventListener. It works fine. My problem arose when I wanted to trigger the event programmatically from another

18条回答
  •  难免孤独
    2020-11-21 05:02

    Use jquery event call. Write the below line where you want to trigger onChange of any element.

    $("#element_id").change();
    

    element_id is the ID of the element whose onChange you want to trigger.

    Avoid the use of

     element.fireEvent("onchange");
    

    Because it has very less support. Refer this document for its support.

提交回复
热议问题