jQuery - How do I bind events to hidden elements that will be shown later?

后端 未结 6 1157
花落未央
花落未央 2020-12-08 00:15

I am trying to attach \'click\' events to all elements of a particular class. The problem is some of the elements are on a tab that is hidden (display: none) at the time tha

6条回答
  •  北海茫月
    2020-12-08 00:52

    edit 2 years later: As some people pointed out, the Live function is now deprecated (as you can also see at the top of the linked docs page). The right event handler name for the current version would be On. See Maxim's answer for a good example.

    Original answer:
    Have you tried using Live()?

    .live('click',function(){/* code */});
    

    ?

    version note: live has been deprecated in jQuery 1.7 and it was removed in jQuery 1.9. This answer is only correct for jQuery versions older than jQuery 1.7

提交回复
热议问题