DEV Community

Ben Halpern
Ben Halpern Subscriber

Posted on

Who still regularly uses jQuery?

Lots of us are still using it for one reason or another. How about you? What's your story?

Oldest comments (98)

Collapse
 
sandeepbalachandran profile image
Sandeep Balachandran

Let Me Have Some Fun

Collapse
 
vinceramces profile image
Vince Ramces Oliveros

One word. "Legacy"

jQuery shines the medieval era of web development.

Collapse
 
fcrozetta profile image
Fernando Crozetta

medieval era of the web development.

This is the most accurate way to describe those times.

Collapse
 
tarasnovak profile image
dataPixy 🧚‍♂️

last time I used it & d3.js 🤣🤣🤣

GitHub logo RandomFractals / droneStrikes

Data viz of US drone strikes in the Middle East




Collapse
 
anuraghazra profile image
Anurag Hazra

Please also add #jokes tag

Collapse
 
tarasnovak profile image
dataPixy 🧚‍♂️

👎👎👎

Collapse
 
skydevht profile image
Holy-Elie Scaïde • Edited

Not regularly, but I have use jQuery. Mainly where I have a simple web app (A few pages without much logic in them, just showing some content). Going with React would be too much a hassle (You have to maintain consistency within the global state). And the few times I had to work on a Wordpress site (I guess they are why jQuery still have this usage)

Collapse
 
wps13 profile image
Willane Paiva

I use it on daily basis, cause of my current job.

Collapse
 
amandaiaria profile image
Amanda Iaria • Edited

The past 6 months I've been not been using it when I'm not coding in a framework. A lot of things that I thought would be easier aren't that bad in es6.

Though $(selector) will always be nice ... I really don't like the document.querySelectorAll(blah).forEach((eachselector) = { so much for something small });

blah

Collapse
 
merlijnvl profile image
merlijn van lent

To be honest, I have no idea if this is an good idea but...

window.$$ = (selector) => {return document.querySelectorAll(selector);};

Does save a lot of keystrokes on an daily basis and because of the double $ most people would at least think of jQuery and thus that it is some sort of selector.

Collapse
 
aimerib profile image
Aimeri Baddouh

I saw a talk by Wes Bos at JAMstack conf where he did exactly this. Actually he implemented $ for querySelector and $$ for querySelectorAll

I think this is a pretty neat trick, but there's a part of me that always wants to pause and analyze whether it is strictly necessary to expand on the window object needlessly. Do you have any opinions on setting this as a part of the window object vs using a separate function to do this?

Collapse
 
daniel15 profile image
Daniel Lo Nigro

You can always just make your own function called $ :)

Collapse
 
pavelloz profile image
Paweł Kowalski • Edited

This is how my utility looks like for that:

const $ = (s, p = document) => {
  if(/object HTML.*Element/.test(s.toString())) {
    throw new Error('[utils/dom/$] Passed dom element instead of selector (string).');
  }

  return Array.from(p.querySelectorAll(s))
};

export default $;

I even export it as $ because i got so used to it ;-)))

I should note that it always returns an array, so no matter if it returns one element or multiple, you can still have one code to iterate matching elements. And if you need only one because you know there will be only one, [0] saves the day, just like in jquery unwrapping method.

Collapse
 
maxxheth profile image
Maximillian Heth

That's pretty nifty!

I made a slight adjustment that will save you the trouble of having to add [0] to the array if there's really only one instance of that selector.


const $ = (selector, context = document) => {

  if(/object HTML.*Element/.test(selector.toString())) {

    throw new Error('[utils/dom/$] Passed dom element instead of selector (string).');

  }

  if (context.querySelectorAll(selector).length > 0) {

    return [...context.querySelectorAll(selector)];

  } else {

    return context.querySelector(selector);

  }

};

Thread Thread
 
pavelloz profile image
Paweł Kowalski

I had it in previous version, but i value having returned array much more than this. Because i often map, i can safely map over array of one element, but it would throw if i dont have it inside the array. Im huge advocate of that.

Collapse
 
highcenburg profile image
Vicente G. Reyes

What's jQuery?

Some comments may only be visible to logged-in visitors. Sign in to view all comments.