get the value of “onclick” with jQuery?

前端 未结 6 668
耶瑟儿~
耶瑟儿~ 2020-12-09 15:16

Is it possible to get the current value of the onClick attribute of an A tag via jQuery?

For example, I have:



        
6条回答
  •  一向
    一向 (楼主)
    2020-12-09 16:08

    mkoryak is correct.

    But, if events are bound to that DOM node using more modern methods (not using onclick), then this method will fail.

    If that is what you really want, check out this question, and its accepted answer.

    Cheers!


    I read your question again.
    I'd like to tell you this: don't use onclick, onkeypress and the likes to bind events.

    Using better methods like addEventListener() will enable you to:

    1. Add more than one event handler to a particular event
    2. remove some listeners selectively

    Instead of actually using addEventListener(), you could use jQuery wrappers like $('selector').click().

    Cheers again!

提交回复
热议问题