1
2

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.

【メモ】webpack環境下においてonclickで関数が発火しなかった件

Posted at

以下はwebpackを使わない環境であれば普通に動きます
eventはデータ取得のために使ってるだけなので本件とは関係ありません

%ul{onclick: 'hoge(event)'}
  %li ほげ
  %li ひげ
  %li はげ

function hoge(e){
  console.log(e.target);
};

バンドルされないJSファイルを別途用意して、そこに上記関数を書けば動きます。
でもそれではwebpack使ってる意味が無いw
逐一イベントリスナー設定したり、JSによって追加されたDOMでJS発火させる時に便利なonclickが使えないのはきつい。
そして悶絶すること数時間。

window.hoge = function(e){
  console.log(e.target);
};

はい解決!!
@JKL_Prestoさん助かりました!
多謝

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?