首页 > 解决方案 > Visual Studio Code giving error for all my jquery code after the update

问题描述

I was coding and everything was fine then visual studio code got an update and then it ended up like this and it is the latest update as of the time of posting: enter image description here

BTW, I checked the jQuery's file source just to make sure and it was correct.

Ok, @charlietfl sugessted that I should remove $(document).ready(function()); it got better but I still end up with this :
enter image description here

But I thought that using the .ready() was important to make sure that the DOM has loaded fully and then the JavaScript code happen. Are there any alternatives that do the same?

Update and fixed

after looking at the API documentation of the JQuery I found that .ready() function is deprecated should be called like below but it didn't say that the .click() method is deprecated but it was also fixed using this other way of using it and it was the ESLinter that was giving me a hard time:

$(function () {
    function addClass() {
        $("#div1").addClass("divStyled");
    }
    function removeClass() {
        $("#div1").removeClass("divStyled");
    }
    function toggleClass() {
        $("#div1").toggleClass("divStyled pStyled");
    }
    function CSS1() {
        var padding = $("#div1").css("padding-left");
        $("#p2").html(padding);

    }

    $("#btnClick1").on("click", addClass);
    $("#btnClick2").on("click", removeClass);
    $("#btnClick3").on("click", toggleClass);
    $("#btnClick4").on("click", CSS1);
});

标签: jqueryvisual-studio-code

解决方案


Fixed

after looking at the API documentation of the JQuery I found that .ready() function is deprecated should be called like below but it didn't say that the .click() method is deprecated but it was also fixed using this other way of using it and it was the ESLinter that was giving me a hard time:

$(function () {
    function addClass() {
        $("#div1").addClass("divStyled");
    }
    function removeClass() {
        $("#div1").removeClass("divStyled");
    }
    function toggleClass() {
        $("#div1").toggleClass("divStyled pStyled");
    }
    function CSS1() {
        var padding = $("#div1").css("padding-left");
        $("#p2").html(padding);

    }

    $("#btnClick1").on("click", addClass);
    $("#btnClick2").on("click", removeClass);
    $("#btnClick3").on("click", toggleClass);
    $("#btnClick4").on("click", CSS1);
});

推荐阅读