I have a example html menu:
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.