How to add click event by class name?

后端 未结 5 919
野性不改
野性不改 2020-12-31 20:45

I have a example html menu:

  • A
5条回答
  •  [愿得一人]
    2020-12-31 21:12

    Yes. You can bind a click event handler to any set of DOM elements, whether they're selected by class or anything else. The syntax in your example is correct, and the event handler will be bound to each element matched by the selector.

    However, bear in mind that in your example id will be undefined. You would have to use this.id, as this will refer to the element that has been clicked.

提交回复
热议问题