Is not it supposed to get the same result using one method or the other? I added a listener oncick
and only using the second method could actually declare the event listener . Why?
var record = document.querySelector('#record');
record.onclick = function(){
alert("Entrou!");
}
var record2 = $('#record2');
record2.onclick = function(){
alert("Não vai entrar!");
}
<!--UPDATE-->
var record3 = $('#record3');
record3.on('click', function(){ alert('Vai entrar sim!'); });
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js"integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g="
crossorigin="anonymous"></script>
<button type="button" id="record">Record</button>
<button type="button" id="record2">Record 2</button>
<!--UPDATE-->
<button type="button" id="record3">Record 3</button>