How to avoid conflict onclick="..." with your click callback?

Actually there is an element of:

<span onclick="LikeBtn.vote(1, 0, event);" class="lb-a"></span>


I want to throw him in your click callback:

$(document).on('click','.lb-a', function(){
alert('clicked!');
});


But not out. My handler does not see clicks and does not work. As I understand it, there is a conflict with an inline onclick="LikeBtn.vote(1, 0, event);" class="lb-a" >.

Can I use both the click callback?
July 2nd 19 at 18:01
1 answer
July 2nd 19 at 18:03
Solution
Maybe add onclick to another function ?
var getAtt = document.querySelector('lb-a').getAttribute('onclick');
document.querySelector('.lb-a').setAttribute('onclick', getAtt + 'function();');


https://jsfiddle.net/9msmy0jL/1/

Complement your answer. If you use setAttribute it is what was before that onClick will be removed. It will be necessary to take what is there and add in a variable for later use. Then everything works correctly.
Uh. The element using the onclick attribute was specified handler, you override and... is only one - the last one. No? - gustave_Kertzmann52 commented on July 2nd 19 at 18:06
Can work both functions. - Lelah.Friesen59 commented on July 2nd 19 at 18:09
theoretically - no. Can you show a simple example where this works? - gustave_Kertzmann52 commented on July 2nd 19 at 18:12
https://jsfiddle.net/9msmy0jL/ - Lelah.Friesen59 commented on July 2nd 19 at 18:15

Find more questions by tags jQueryJavaScript