Uncaught TypeError: Object n’a pas de méthode ‘on’

Quelqu’un peut-il m’aider à comprendre cela?

Lorsque j’utilise la dernière version (ou une version plus récente) de jQuery, le petit script ci-dessous fonctionne correctement. Cependant, lorsque j’utilise les anciennes versions de jQuery, mon script indique que la fonction on n’existe pas.

Voici mon script qui ne fonctionne pas avec les anciennes versions de jQuery:

 $(document).ready(function () { $(".theImage").on("click", function(){ // In the event clicked, find image, fade slowly to .01 opacity $(this).find("img").fadeTo("slow", .01).end() // Then, of siblings, find all images and fade slowly to 100% opacity .siblings().find("img").fadeTo("slow", 1); }) }) 

Toute aide est appréciée.

    Vous devez utiliser bind au lieu de on , car on n’a été introduit que dans jQuery 1.7 .

     $(document).ready(function () { $(".theImage").bind("click", function(){ // In the event clicked, find image, fade slowly to .01 opacity $(this).find("img").fadeTo("slow", .01).end() // Then, of siblings, find all images and fade slowly to 100% opacity .siblings().find("img").fadeTo("slow", 1); }) }) 

    Vous pouvez utiliser delegate() , par exemple:

     $("table").delegate("td", "click", function() { $(this).toggleClass("chosen"); }); 

    Ceci est équivalent au code suivant écrit en utilisant on() :

     $("table").on("click", "td", function() { $(this).toggleClass("chosen"); }); 

    Vous devez utiliser jQuery version 1.7+ pour utiliser on() . bind() est obsolète.

    Modifiez la fonction on pour bind :

    .children().on("click",function()
    à
    .children().bind("click",function()