Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
});
like image 784
M.Amin Avatar asked Feb 16 '26 23:02

M.Amin


1 Answers

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);
});
like image 106
M.Amin Avatar answered Feb 19 '26 15:02

M.Amin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!