Live data from Hacker News

Ask HN: Any Modern Alternative to JQuery?

news.ycombinator.com

11–20 of 26 posts

Re: Ask HN: Any Modern Alternative to JQuery?

#11

Earlier quoted context omitted.

> Every problem jQuery solved has been standardized into native javascript Some problems, sure. Every problem? I think that's a stretch. Jquery still has it's applicability and can in some cases lead to simpler code.

Like what? The main purpose of jQuery was to have a unified API for dealing with the issue of every browser having their own quirky implementation of the web standard. All of those are gone today and we now have a pretty much standardized Javascript that you can write once and run in any browser.

I never used jQuery, but it seems that two other problems that is solved and that current browsers largely cover now are:

- easier AJAX requests (fetch does this)

- selecting nodes using CSS-like selectors (querySelector / querySelectorAll)

Hiding elements too: HTML now has the hidden attribute. Maybe manipulating HTML/CSS classes? (classList has everything)

Re: Ask HN: Any Modern Alternative to JQuery?

#12

Unless there is code which explicitly needs jQuery, most bindings/helpers are available here: http://youmightnotneedjquery.com/ Since you're building such a website, a common option for you may be to use a lightweight framework like Svelte/Sapper as your client. I've been using this for most projects with a Django backend.

Svelte is nice, and pages can be rendered server side for the initial rendering, which is nice for progressive enhancement. They have a nice tutorial : https://svelte.dev/tutorial/

I'd consider vanilla JS anyway and switch to a framework if things get too complicated.

edit: one can go a very long way with just HTML/CSS now, and this allows very fast and accessible websites.

Re: Ask HN: Any Modern Alternative to JQuery?

#13

You don't need jQuery. Every problem jQuery solved has been standardized into native javascript so you can just use Javascript to build web apps. For example instead of $(".button"), you can do document.querySelector(".button"), and so on. That said, if you must use a framework and looking for something less complicated than react, look into Vue or Svelte.

That does not solve the problem because jQuery spaghetti comes from developing features. Equivalent native commands must accumulate the same increasing complexity.

Re: Ask HN: Any Modern Alternative to JQuery?

#16

Vanilla JavaScript is what you need today. You can use document.querySelector, Array.prototype.map, fetch, and all browsers have the same behaviour so no need for any library like jQuery anymore.

Feature parity isn't exactly the reason to drop it....

$ is easier to type than document.querySelector and it absorbs browser differences.

Re: Ask HN: Any Modern Alternative to JQuery?

#17
post #16

Vanilla JavaScript is what you need today. You can use document.querySelector, Array.prototype.map, fetch, and all browsers have the same behaviour so no need for any library like jQuery anymore.

Feature parity isn't exactly the reason to drop it.... $ is easier to type than document.querySelector and it absorbs browser differences.

You don't download an entire library to save you some keystrokes. Just create your own $ alias if you must.

Re: Ask HN: Any Modern Alternative to JQuery?

#18
You can create a react site in a couple minutes using create-react-app. React has JSX which allows you to do basically everything JQuery could without hacks.

Fetch or one of the wrapper libraries has HTTP covered.

Typescript is great if you want everything to work seamlessly on older browsers while using modern JS.

Yeah it's a lot to learn but once you know it, it's just as efficient as the old "JQuery forests + HTML" and way more maintainable.

I did ASP.NET MVC for years and once I learned React + Angular I never looked back. They work just like the desktop UI libraries of old, which is a good thing.

Django and related "server side" frameworks are functionally obsolete unless you have a very static website that needs perfect SEO (ex blog, news site)

Re: Ask HN: Any Modern Alternative to JQuery?

#19
post #17
post #16

Earlier quoted context omitted.

Feature parity isn't exactly the reason to drop it.... $ is easier to type than document.querySelector and it absorbs browser differences.

You don't download an entire library to save you some keystrokes. Just create your own $ alias if you must.

It's not just $...

And why not just install jQuery? What's the big deal?

Where can I find the short aliased library? (If it's not there, I guess it's not a popular idea.)

Re: Ask HN: Any Modern Alternative to JQuery?

#20

I want to try this soon: https://htmx.org/ htmx allows you to access AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext htmx is small (~9k min.gz'd), dependency-free, extendable & IE11 compatible

Playing with it now, one annoyance is that it operates on names, not ids. E.g., if you have a

    
You can't set statusbox as the hx-target and expect it to work.
Post reply on HN