How to add click event by class name?

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

I have a example html menu:

  • A
5条回答
  •  难免孤独
    2020-12-31 21:25

    If I understand your question correctly, try using this:

    $('.menu_button').click(function() {
         if ( $(this).attr('id') == "m1" ) ....
     })
    

    Btw: In this case, a switch .. case would be far more appropriate!

提交回复
热议问题