JavaScript and jQuery


#1

Continuing the discussion from Tracking Scene Loads in Google Analytics:

@Photics

Hi Mark!

I see things from the other end of the telescope. jQuery simplifies Javascript coding for me.

Example:
A <div> tag with an ID of ‘slideshow’:  $('#slideshow img').hide();

This bit of jQuery automatically loops through all the images (whatever the number) in the div and hides them - sweet & tight.

What would your Javascript look like to accomplish the same task?


(𝕄𝕚𝕔𝕙𝕒𝕖𝕝 𝔾𝕒𝕣𝕠𝕗𝕒𝕝𝕠) #2

Did you mean me or @MarkHunte

Well, if I was using Drupal or WordPress, I might just plug into jQuery. However, I could just manipulate DOM elements by class…

I was about to go to sleep, so I obviously didn’t test it out. Sure, the code is somewhat longer, but then I don’t have a reliance on another file. That might not seem like a big issue, but that depends on how the jQuery file is delivered. If you self-host, that’s a ~90K download for the minified version. That’s not a disaster, but I’d probably avoid it to speed up the download. It depends how much work I’d save and how much space I’d save by writing in pure JavaScript.

The bigger trouble is with a CDN. That third-party hosting the file for you can learn a lot about your visitors.

If you missed it, here’s a link to a helpful website… http://youmightnotneedjquery.com

It’s not that jQuery is bad. It’s about knowing when to use it. If you’ve weighed the benefits and the drawbacks, and then chose jQuery for your project, that’s good. If it’s the first thing you use, even if you don’t need it, that can hurt your growth as a developer.


#3

Hi Michael!

Thanks for the reply - and I did mean You, not Mark, sorry!