Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Vanilla JS is quite nice these days, the only advantages jQuery has now is the fact that it's somewhat less verbose for DOM things and has support for old browsers.

  // For example, instead of
  $("#somebutton").click(() => alert("Hello"))

  // You would  do
  document.querySelector("#somebutton").addEventListener("click", () => alert("Hello"));
  
  
  // Instead of
  $("#message").text("Important Message")

  // You would  do
  document.querySelector("#message").textContent = "Important Message";
  
  
  // Instead of
  $("#things .thing").css("color", "red")

  // You would  do
  for(let e of document.querySelectorAll("#things .thing")) e.style.color = "red";
  
  
  // Instead of
  await $.ajax("https://httpbin.org/get").then((_1, _2, {responseJSON}) => responseJSON)

  // You would  do
  await fetch("https://httpbin.org/get").then(e => e.json())


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: