get the value of “onclick” with jQuery?

前端 未结 6 679
耶瑟儿~
耶瑟儿~ 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 15:48

    Could you explain what exactly you try to accomplish? In general you NEVER have to get the onclick attribute from HTML elements. Also you should not specify the onclick on the element itself. Instead set the onclick dynamically using JQuery.

    But as far as I understand you, you try to switch between two different onclick functions. What may be better is to implement your onclick function in such a way that it can handle both situations.

    $("#google").click(function() {
        if (situation) {
            // ...
        } else {
            // ...
        }
    });
    

提交回复
热议问题