Skip to content

Instantly share code, notes, and snippets.

@annelyse
Created January 6, 2023 16:02
Show Gist options
  • Save annelyse/02eb3d14ecb0088909883b46dd1a9252 to your computer and use it in GitHub Desktop.
Save annelyse/02eb3d14ecb0088909883b46dd1a9252 to your computer and use it in GitHub Desktop.
/**
* Simulate a click event.
* @public
* @param {Element} elem the element to simulate a click on
*/
var simulateClick = function (elem) {
// Create our event (with options)
var evt = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
// If cancelled, don't dispatch our event
var canceled = !elem.dispatchEvent(evt);
};
const falseClick = document.querySelector('.falseClick');
if( falseClick ){
falseClick.addEventListener('click', event => {
console.log( 'click' );
const link = document.querySelector('#wp-live-chat-by-3CX');
console.log(link );
simulateClick(link);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment