2
0

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.

JavaScriptで取得してきたDOMにイベントをトリガーするワンライナー

Last updated at Posted at 2019-11-13

メモ書きです
Chrome DevToolsなどで実行すると幸せになるひとがいるかもです

取得した一つ目の要素に対して実行

document.querySelector('.className').dispatchEvent(new Event('mouseover', { 'bubbles': true }));

取得した全ての要素に対して実行

document.querySelectorAll('.className').forEach(e => {e.dispatchEvent(new Event('mouseover', { 'bubbles': true }))});

補足

  • .classNameの箇所はCSSセレクターを指定しDOMを取得します
  • mouseoverの箇所は実行するイベントを指定します
  • IEでは起動しなさそう

参考

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?