1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

create event and dispatch

Posted at

Event objectの作り方メモ。

function _click(e) {
    console.log(e);
    alert('Clicked!');
}

function _loaded(e) {
    
    var evt = document.createEvent('MouseEvent');
    
    evt.initMouseEvent(
	'click', //type
	true,    //canBubble
	true,    //cancelable
	window,  //view
	0,       //detail
	0,       //screenX
	0,       //screenY
	0,       //clientX
	0,       //clientY
	false,   //ctrlKey
	false,   //altKey
	false,   //shiftKey
	false,   //metaKey
	0,       //button
	null     //relatedTarget
    );
    
    //execute a 'click' event.
    document.dispatchEvent(evt);
}

document.addEventListener('click', _click, false);
document.addEventListener('DOMContentLoaded', _loaded, false);
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?