Search code examples
jqueryclickmessagedeprecated

Hoe to rewrite this code to avoid jQuery click deprecated message?


Can anybody advise me how to rewrite this piece of js code to avoid the jqmigrate click deprecated warning message?

                    return $("<li/>").append($("<a/>", {
                        "class": item["class"],
                        text: item.text,
                        click: function (event) {
                            item.click.call(this, item, event);
                        }
                    }));

No matter how I rewrite this code it keeps on telling me JQMIGRATE: jQuery.fn.click() event shorthand is deprecated

If I turn off JQMigrate all works also just fine.


Solution

  • The answer is this

                return $("<li/>").append($('<a/>').attr("class", item["class"]).text(item.text).on('click', function(event){item.click(item,event);}));