Live data from Hacker News

You Don't Need JQuery

blog.garstasio.com

31–40 of 201 posts

Re: You Don't Need JQuery

#31
post #7

You can basically sum up this entire rather ridiculous site with "Yes, you don't need jQuery, you can just use the built-in methods, but using jQuery is generally more pleasant, more consistent, and involves less typing". One particularly egregious example from the site: $('#foo').removeClass('bold'); vs. document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); The au…

I honestly just called bullshit and stopped reading after the first example (selecting elements by id).

Re: You Don't Need JQuery

#32
post #23

Earlier quoted context omitted.

`$(".foo").removeClass("bold")` becomes the wonderfully concise [].map.call(document.querySelectorAll(".foo"), function(node) { node.classlist.remove("bold"); })

This may seem anecdotal, but I can tell you from writing a lot of non-jQueryified code that with modern browsers, applying classes to dozens of elements dynamically can be an anti-pattern. 99% of the time, when doing something which previously would have required that, I can use a single class on a parent element.

Not if you're in an environment (like mobile) where you want to reduce repaint.

Re: You Don't Need JQuery

#33
post #17

Every time I try to build something without jQuery, I regret it. Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements. No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically gene…

There are other libraries though which provide (IMHO better) implementations of each of those things. jQuery has been around for ten years and has to remain backwards compatible. It's just not possible for it to be the best implementation of Promises, or AJAX or any of the other individual things it does. Real bundling with tools like Browserify is making it more and more feasible to use single-purpose libraries inst…

> There are other libraries though which provide (IMHO better) implementations of each of those things. jQuery has been around for ten years and has to remain backwards compatible. It's just not possible for it to be the best implementation of Promises, or AJAX or any of the other individual things it does.

I agree with all those things. jQuery is the lowest common denominator. It's the best at nothing, bloated with support for Palm Pilot browsers and Safari 1.0, and doesn't have all the cool grunt/gulp/amd/broccoli/cucumber/jsx/fotm neologisms. If I'm building a new, long-term project, I'm going to evaluate all the options, and craft the best possible technology stack for my new app.

But sometimes worse is better. Like a smooth pebble pulled out of a stream, it's taken a long journey and had most of the rough edges rubbed off. It's already in your browser cache from 4 different CDNs. Someone else can pick it up and support it easily. And that's what often makes it the best choice, when you want to avoid bikeshedding over what the hottest new thing is, and just make a webpage.

jQuery may not be the best technology, but it's a sane default.

Re: You Don't Need JQuery

#34

Every time I try to build something without jQuery, I regret it. Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements. No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically gene…

Life is definitely too short to not be using npm, browserify and React!

https://www.npmjs.com/package/browserify

https://www.npmjs.com/package/react

And then use just what modules you need. All the functionality of jQuery has already been ported to various modules.

https://www.npmjs.com/package/extend

https://www.npmjs.com/package/promise

https://www.npmjs.com/package/serialize-form

Re: You Don't Need JQuery

#36
post #7

You can basically sum up this entire rather ridiculous site with "Yes, you don't need jQuery, you can just use the built-in methods, but using jQuery is generally more pleasant, more consistent, and involves less typing". One particularly egregious example from the site: $('#foo').removeClass('bold'); vs. document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); The au…

The second function is broken for an element with multiple classes. DOM fail.

Re: You Don't Need JQuery

#37

Every time I try to build something without jQuery, I regret it. Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements. No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically gene…

Yeah, the problem with jQuery is all that other stuff that nobody uses and backwards compatibility with browsers nobody supports. A "lite" jQuery with the same familiar API but a stripped-down featureset for higher performance and smaller size would be nice.

Re: You Don't Need JQuery

#38

Every time I try to build something without jQuery, I regret it. Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements. No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically gene…

React handles event normalization, fyi.

Re: You Don't Need JQuery

#39

Every time I try to build something without jQuery, I regret it. Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements. No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically gene…

Life is definitely too short to not be using npm, browserify and React! https://www.npmjs.com/package/browserify https://www.npmjs.com/package/react And then use just what modules you need. All the functionality of jQuery has already been ported to various modules. https://www.npmjs.com/package/extend https://www.npmjs.com/package/promise https://www.npmjs.com/package/serialize-form

> Life is definitely too short to not be using npm, browserify and React!

These are all cool things, but sometimes you want to simply make a web page without setting up node and npm and all that jazz.

Think of it this way... jQuery is like getting a subset of the most common functions you get by using in browserify, but without requiring a build step!

Re: You Don't Need JQuery

#40
post #37

Every time I try to build something without jQuery, I regret it. Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements. No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically gene…

Yeah, the problem with jQuery is all that other stuff that nobody uses and backwards compatibility with browsers nobody supports. A "lite" jQuery with the same familiar API but a stripped-down featureset for higher performance and smaller size would be nice.

Zepto might be what you are looking for.

http://zeptojs.com/

Post reply on HN