jQuery id selector works only for the first element

后端 未结 7 2089
借酒劲吻你
借酒劲吻你 2020-11-22 02:55

I have 3 buttons with same id, I need to get each button value when he\'s being clicked.

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 03:34

    If you have same id in a container you can use on() to access each element for every event

    $("#containers").on("click","#xyz",function(){
      alert($(this).val())
      })
    
    
    

    and info about on() is here

提交回复
热议问题