How to add click event by class name?

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

I have a example html menu:

  • A
5条回答
  •  梦毁少年i
    2020-12-31 21:03

    I would suggest to use the live function, instead of the .click, because the elements added on run-time will also be clickable.

    $('.menu_button').live('click', function() {
      var id = $(this).attr('id');
      if (id == "m1") {
          //do your stuff here
      }
    });
    

提交回复
热议问题