Posts

Showing posts with the label What is difference between click and onclick in jquery

What is difference between click and onclick in jquery

Image
What is difference between click and onclick in jquery I would prefer .on over .click because the former can use less memory and work for dynamically added elements, A simple  difference between click and onclick in jquery. . <html>     <button id="add">Add new</button>     <div id="container">         <button class="alert">alert!</button>     </div> </html> where we add new buttons via - <script> $("button#add").click(function() {     var html = "<button class='alert'>Alert!</button>";     $("button.alert:last").parent().append(html); }); // click $("button.alert").click(function() {     alert(1); }); // on click $("div#container").on('click', 'button.alert', function() {     alert(1); }); </script> '.click' Clicks for cli...