Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of getPreventDefault() is deprecated. Use defaultPrevented instead. Why I'm getting this error and what's the solution for it?

Previously I was using jQuery 1.7.1 in my code. I was getting the above error. Then I used the jQuery 1.11.1 straight from the google repository

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js">
</script>

but still I'm getting this error. How should I resolve this?

Due to this error my other jQuery functionality is also not working.

I researched a lot about the solution but every time I got the same solution of upgrading the jQuery version. But this is also not working for me.

like image 738
PHPLover Avatar asked Oct 03 '14 10:10

PHPLover


3 Answers

Try:

event.originalEvent.defaultPrevented

As in:

$(document).on('click', function (e) {
    if (e.originalEvent.defaultPrevented) return;
    // continue
});
like image 92
cuth Avatar answered Oct 24 '22 03:10

cuth


I get this error with PHPStorm debugging with Firefox 2.8 when using jQuery, currently jquery-2.0.2.min. On examining the file, it contains the following statement:

this.isDefaultPrevented=e.defaultPrevented||e.getPreventDefault&&e.getPreventDefault()?U:Y

if you change this to:

this.isDefaultPrevented=e.defaultPrevented?U:Y

the warning stops.

like image 5
markl139 Avatar answered Oct 24 '22 04:10

markl139


I have also come across this problem and found that with jQuery 1.x the replacement

event.defaultPrevented;

does not work at all, but the original

event.getPreventDefault();

still works as expected but does throw a warning on Firebug. I guess someone somewhere expects everyone to upgrade to jQuery 2.x eventually. This shouldn't be a fatal or critical error for you, simply a warning, and in this instance that the replacement feature doesn't work on jQuery 1.x then it's suitable to bare this in mind but not act upon this warning.

like image 4
Martin Avatar answered Oct 24 '22 03:10

Martin