Live data from Hacker News

You Don't Need JQuery

blog.garstasio.com

51–60 of 201 posts

Re: You Don't Need JQuery

#51
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.

That makes the site a pretty good illustration of one of the reasons why, although you don't have to use jQuery, you maybe should. With jQuery you benefit from years of development and testing, which your own code probably hasn't undergone.

Re: You Don't Need JQuery

#52
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.

Just use the CDN copy of jquery and it will be cached in the users browser already since so many websites already use it.

Re: You Don't Need JQuery

#54
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…

also it hides the discrepancies between the various browsers

Re: You Don't Need JQuery

#56
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…

.classlist() [1] is coming [2]. It'll allow you to do: document.getElementById('foo').classList.remove("bold"); Sure, it's still more verbose. But a lot of what jQuery does is slowly being obsoleted by better native javascript apis. [1] https://developer.mozilla.org/en-US/docs/Web/API/Element.cla... [2] http://caniuse.com/#feat=classlist

before jQuery I always defined an ID method like:

   function ID(id) { return document.getElementById(id); }
saved some typing. I'll always try to use jQuery now though, bigger problems to solve.. few extra bytes to download is not that bad...

Re: You Don't Need JQuery

#57
I do need JQuery because I want to focus on the application and not nuances of different js implementations. And I want to use the simple selector mechanisms. Then there's plugins, I use those too and many assume/require JQuery.

So no, I disagree. Stupid article.

Re: You Don't Need JQuery

#58
post #15

Another great resource when trimming down jquery use is http://youmightnotneedjquery.com/

...and then, of course, there's:

http://youmightnotnotneedjquery.com/

or

https://gist.github.com/rwaldron/8720084#file-reasons-md (discussion: https://news.ycombinator.com/item?id=7153630)

Re: You Don't Need JQuery

#59

Earlier quoted context omitted.

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!

This is about more than just a build process.

jQuery's imperative DOM manipulation is a horrible way to manage state compared to React.

These tools aren't just "cool things". They were designed to solve really pressing issues related to managing complexity in front-end web applications by eliminating global state in both the DOM or the JS runtime environment. They tend towards a more declarative and functional approach to system design.

A build process that integrates with a versioned package manager is fantastic.

Post reply on HN