Internet Explorer Object doesn’t support property or method ‘preventDefault’
I was working on a web page where I need to show or hide a div on button click using jquery, very simple code like below:
1 2 3 4 5 6 |
$(function () { $('#btntest').click(function () { event.preventDefault(); $('#testdiv').toggle(); }); }); |
it was working fine in chorme browser, but in IE I get the error like Object doesn’t support property or method ‘preventDefault’
at first I started thinking is it a problem of IE, but as Jquery is well established library I had to think that there is something wrong in my code, then I started checking and I found without passing the event object parameter in the function and I was calling event.preventDefault();
so the fixing was also very simple I just have to pass the event object as parameter…
1 2 3 4 5 6 |
$(function () { $('#btntest').click(function (event) { event.preventDefault(); $('#testdiv').toggle(); }); }); |