I'm just wondering if anyone can point out why you should use jQuery event bindings rather than native JavaScript. My colleague sent me the following code.
document.forms[0].onsubmit = function () { if (Page_IsValid) { $("#dialog").dialog({ height: 140, modal: true, resizable: false, title: '' }); $(".ui-dialog-titlebar").hide(); } }
And I told him to rewrite it as.
$(".form").submit(function () { if (Page_IsValid) { $(".dialog").dialog({ height: 140, modal: true, resizable: false, title: '', open: function (event, ui) { $(".ui-dialog-titlebar").hide(); } }); } });
But when the question arises as to why my code should be used, I could not indicate any specific reason, except for syntactic clarity and agreement. So are there any other reasons why the second example could be used compared to the first? If not, then what is the real advantage of using jQuery in this case?
source share