Getting rid of jQuery

A Web Developer based in Belgium, specialized in PHP & JS development
Search for a command to run...

A Web Developer based in Belgium, specialized in PHP & JS development
No comments yet. Be the first to comment.
I recently needed to collect all changes in one file for reporting purposes. Found this article: https://ratfactor.com/cards/git-diff-with-new-files In case you need something similar on Windows, here

Some projects start with a grand plan. Others start because you just need to read a file without thinking too much about it. That was the case for spread-compat. I needed a common interface for CSV, X

With modern css, you can almost get rid of sass. But there is one last pain point : media queries. Not being able to use variables or an easy, common syntax for typical breakpoints is really annoying. That is, until you meet Media Queries Level 5. I’...

This is a quick article to share this demo I just made. https://codepen.io/lekoalabe/pen/JoPNWpX

Modals are typical UI elements for many web apps. There are countless packages dedicated to that specific features, each framework creating its own variation. Popular frameworks like Bootstrap also have custom code to deal with it. But all this feels...

With the upcoming arrival of Bootstrap 5 , more and more sites will be able to do without jQuery. For a long time I used jQuery, I found it convenient, but with today's performance requirements that directly impact SEO, every little ms is a ms gained.
A classic example is the use of the document.ready..., which is actually useless. I f you use a defer on your scripts (hint: you should!), they are already executed when the dom is ready... no need to add a layer.
One thing that we often find ourselves doing, is to loop on a list of elements of the dom. In modern native javascript (IE11+) nothing could be easier:
document
.querySelectorAll(selector)
.forEach(function (item) {
item.addEventListener("click", function (e) {
e.preventDefault();
console.log(item);
});
});
Another classic example is sticky headers. Why use jQuery when a few lines are enough?
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
Or do you just want to show or hide a block? Here is another example
item.addEventListener("click", function (e) {
e.preventDefault();
var t = document.querySelector(this.getAttribute("href"));
if (window.getComputedStyle(t).display === "none") {
t.style.display = "block";
} else {
t.style.display = "none";
}
});
Note the "getComputedStyle" that lets you know whether the element is visible or hidden, whether it is via the style attribute or a css class.
What would jQuery be without its famous plugins! Fortunately more and more javascript components take a multi framework approach and are essential written in "pure" javascript with just a wrapper around it to react, view, angular... Well, not all of them unfortunately, there are still some components that are written only for a given library.
I recently published ModularBehaviour.js which allows to attach a javascript behavior to a given node. Currently, it also works with jQuery plugins, but eventually when I will have found alternatives for all my plugins, I plan to do this in "pure" js.
Happy coding to all of you!