0
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 3 years have passed since last update.

Javascriptでボタンのクリックを待ち受ける方法

Posted at

ボタンが押されるまで待ち受けて、押されたボタンの種類を返す処理

waitForClick() {
  return new Promise((resolve, reject) => {
    document.getElementById('button1').onclick = () => resolve('button1');
    document.getElementById('button2').onclick = () => resolve('button2');
  });
}

const result = await waitForClick();

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