Javascript click event listener on multiple elements and get target ID

前端 未结 6 1298
轻奢々
轻奢々 2020-12-01 22:06

I have a javascript file that sets an EventListener of \'click\' on every element with the

tag. I want to get the id of the article clicked when
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 22:22

    articles.addEventListener('click',redirect,false); // omit redirect(e) inside event listener // and then try with the alert as you did.
    

    if does not work then try by e.id instead of e.target.id inside alert as below:

       alert(this.id);
    

    Thanks.

提交回复
热议问题