Pages

Invoking mouse events through JavaScript

Handling Mouse Events through Java script

In some scenarios, we may need to invoke a button click through script. We can write element.click(), but that will not work in all the browsers. We may need to do this in another way, please check the below code snippet.


function invokeSaveClick(saveElementId) {
    var e = document.createEvent('MouseEvents');
    e.initEvent('click', true, true);
    document.getElementById(saveElementId).dispatchEvent(e);
}

No comments:

Post a Comment