jquery - 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:
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 :
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);
});
解决方案
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);
});
推荐阅读
- c# - 我可以使用 WIFI 天线捕获信号,例如 IMSI Catcher 吗?
- ruby - 为 Ruby FFI::Struct 定义一个初始化方法?
- python-3.x - 通过循环制作tkinter按钮后,按钮不可点击
- c++ - 从双打向量中找到多种模式
- typescript - 如何为一组输入定义类型,这些输入映射到 TypeScript 中函数的一组输出?
- powershell - Powershell:调用Parent的空构造函数的继承类,即使传递了对象
- java - Java:为什么 else 语句总是在我的 while 循环中运行?
- python - Python Pandas 复合聚合不等于单个资产复合的总和
- python - 如何计算 Sklearn 中点到质心的平均距离的平均值?
- r - 如何使用列名向量作为 dplyr::group_by() 的输入?