DEV Community

[Comment from a deleted post]
Collapse
 
cescquintero profile image
Francisco Quintero 🇨🇴 • Edited

I now there are better tools out there but how is this a good example of not using jQuery?

// jQuery
$.post('//example.com', { username: username }, function (data) {
  // code
})

// Vanilla
var httpRequest = new XMLHttpRequest()
httpRequest.onreadystatechange = function (data) {
  // code
}
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
httpRequest.open('POST', url)
httpRequest.send('username=' + encodeURIComponent(username))
Enter fullscreen mode Exit fullscreen mode

The thing with jQuery is that its API is very clean and easy to remember. Go try traversing some DOM nodes without knowing the property names.

I can't see why people can't use jQuery today. It works, many bugs solved, lots of useful libraries (sadly abandoned), powerful and simple API. jQuery, for DOM traversing, IMO, it's way more powerful and expressive than the vanilla counterpart. Hey, IMO.

Of course not ideal for a SPA but you just can't discard it. More if sites like "You don't need jQuery anymore" use examples like the one for the vanilla POST request.

I say this as a backend that coded jQuery in the past and not much today but have got experience with React and Ember and know they're not for the same thing.

Don't compare them, enjoy them :D