Add Event Listener to Collection of HTML Elements

前端 未结 8 2074
执念已碎
执念已碎 2020-12-03 18:40

I know that getElementsByTagName and getElementsByClassName need an index identifier in order for the objects to be bound to an event listener.

8条回答
  •  無奈伤痛
    2020-12-03 19:38

    You can use the class too as a selector.

    var elems = document.getElementsByClassName('inputs');
    

    Then loop over these to attach event handlers.

提交回复
热议问题