224

I have this script:

<script>
$(document).ready(function () {
    $("#changeResumeStatus").click(function () {
        $.get("{% url 'main:changeResumeStatus' %}", function (data) {
            if (data['message'] == 'hidden') {
                $("#resumeStatus").text("скрыто");
            } else {
                $("#resumeStatus").text("опубликовано");
            }
        }, "json");
    });
});
</script>

I receive the following error in my Google Chrome console:

event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

I am using jQuery v1.10.2 and #changeResumeStatus is a <span>.

What's wrong with my script?

Alex Parakhnevich
  • 5,172
  • 4
  • 26
  • 30
  • 19
    I think that's not an error, but merely a warning - this one can be safely ignored. – Qantas 94 Heavy Nov 18 '13 at 10:14
  • 32
    This warning is following lastest chrome update, don't worry – A. Wolff Nov 18 '13 at 10:15
  • 2
    You should look into escaping non-ascii strings. – Gleno Nov 21 '13 at 09:12
  • @Gleno what for? my templates work completely fine in utf-8 – Alex Parakhnevich Nov 21 '13 at 09:32
  • 4
    @AlexParakhnevich There's no single compelling reason to do so, but a few minor ones that creep up from time to time. My reaction was instinctive rather than well thought out, to be honest. In projects I'm working on right now, there's a guideline to not use non-ascii chars in literals, which I instituted in the past, because some external tools (typescript compiler) choked on such input. It works well enough in most cases, but sometimes eats up a lot of developer time when things go wrong. Anyway, `.empty().append("text")` is better expressed as `.text("text")`. – Gleno Nov 21 '13 at 09:50

7 Answers7

204

This is only a warning: your code still works, but probably won't work in the future as the method is deprecated. See the relevant source of Chromium and corresponding patch.

This has already been recognised and fixed in jQuery 1.11 (see here and here).

Peter Souter
  • 5,110
  • 1
  • 33
  • 62
Paul Mougel
  • 16,728
  • 6
  • 57
  • 64
  • 12
    I doubt this anyone will break this anytime soon if it means causing all pages using JQuery < 1.11 to break. – Backpackcoder Nov 27 '13 at 02:25
  • 26
    This warning also appears with jQuery 2.0.3 (most recent stable as of this comment), and the current milestone is set to 2.1, for the fix. – counterbeing Dec 09 '13 at 21:18
  • Does using jQuery 1.11 will fixe the issue? – Krunal Mar 05 '14 at 13:05
  • Just to clarify... `jQuery` has *not* deprecated using `return false` in your click handlers? This is *Chrome* complaining about a snippet of code found inside the jQuery library? – mpen Mar 06 '14 at 00:08
  • 2
    Indeed. Chrome has deprecated `event.returnValue` which only existed for backwards compatibility with IE – Paul Mougel Mar 06 '14 at 07:07
  • I got the same error message by merely having `console.log(x)`, where x was mouseEvent (onclick). Chrome 33.0.1750.154. I'd consider it's a bug on Chrome's side by triggering the warning too loosely. – F-3000 Mar 27 '14 at 13:12
  • @F-3000 It is not a bug on Chrome's side. When you use jQuery, Chrome loads the jQuery library and parses it exactly like it would for a script you supplied. If you include jQuery, it will see that event.returnValue is used, and (correctly) throw the warning. – iCodeSometime Apr 22 '14 at 21:58
  • @kennycoc If jQuery actually had `event.returnValue`, then it indeed was jQuery's fault. But getting this warning with `console.log(mouseEvent)` definitely is a bug, as it very effectively disturbs debugging. – F-3000 Apr 23 '14 at 07:06
  • Sorry, I guess I misunderstood what you were saying – iCodeSometime Apr 23 '14 at 12:34
23

Just for other's reference, I just received this and found it was due to AngularJS. It's for backwards compatibility:

if (!event.preventDefault) {
    event.preventDefault = function() {
        event.returnValue = false; //ie
    };
}
Ledivin
  • 637
  • 5
  • 18
  • 4
    I'm getting the error in a bare bones site with no angular being used or referenced - possibly indirectly referenced, but I doubt it. – B. Clay Shannon-B. Crow Raven Nov 27 '13 at 14:22
  • 1
    @B.ClayShannon: It's not an error, it's a warning. There's a big difference, especially in our context. You can safely ignore it. – f.ardelian Dec 14 '13 at 22:18
  • 1
    @B.ClayShannon If you include it at all, Chrome will parse it exactly the same as if it was a script you supplied, and (correctly) throw the warning. – iCodeSometime Apr 22 '14 at 21:33
20

If you using Bootstrap:

The current version of Bootstrap (3.0.2) (with jQuery 1.10.2 & Chrome) seems to generate this warning as well.

(It does so on Twitter too, BTW.)

Update

The current version of Bootstrap (3.1.0) no longer seems to generate this warning.

ensignr
  • 297
  • 1
  • 5
19

That's your jQuery API problem, not your script. There is not much to worry about.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Victor Zhang
  • 211
  • 1
  • 5
6

This is a warning related to the fact that most JavaScript frameworks (jQuery, Angular, YUI, Bootstrap...) offer backward support for old-nasty-most-hated Internet Explorer starting from IE8 down to IE6 :/

One day that backward compatibility support will be dropped (for IE8/7/6 since IE9 deals with it), and you will no more see this warning (and other IEish bugs)..

It's a question of time (now IE8 has 10% worldwide share, once it reaches 1% it is DEAD), meanwhile, just ignore the warning and stay zen :)

numediaweb
  • 16,362
  • 12
  • 74
  • 110
  • jQuery 2.x.x only supports IE9 and up. If you want IE8 support in jQuery you need to use version 1.x.x. – Pete Jan 31 '14 at 19:29
3

I saw this warning on many websites. Also, I saw that YUI 3 library also gives the same warning. It's a warning generated from the library (whether is it jQuery or YUI).

Nick Rippe
  • 6,465
  • 14
  • 30
eAbi
  • 3,220
  • 4
  • 25
  • 39
3

I found that using the latest version will fix this problem:
http://code.jquery.com/jquery-git.js