JS event listener for a type of element?

前端 未结 5 1738
野趣味
野趣味 2021-01-22 18:47

Is there a way to add some kind of listener for a type of html element? For example if i wanna call a function when the user clicks any p element

5条回答
  •  天命终不由人
    2021-01-22 19:17

    the easiest answer would be using addEventListener() if you want a specific html tag just like what i wanted in my question then you'll find the answer there ill paraphrase it here too add this

    to the end of your document by the way don't forget to use uppercase nodeNames or just put a toLowerCase() before it. cheers :)

提交回复
热议问题