Suppose I have a div and I want to make a certain code run when a user clicks on that div. I can accomplish that in 2 ways.

HTML

<div id="clickme">Click Me</div>

Javascript

$(document).ready(function(){
    $('#clickme').click(function(){
        //Other code here doing abc.
    });
});

the 2nd way is calling a function which does exactly that but it is called by a function

<div id="clickme" onclick="clickme()">Click Me</div>

Javascript

function clickme(){
    //Other code doing abc.
}

My question is that are both these codes doing the same thing? and which is more efficient and recommended?

Edit
Report