El Noguer

Joaquim Perez i Noguer

jQuery vs JS

Filed under: Web — Joaquim Perez Noguer at 4:18 pm on Dimecres, Agost 16, 2017

Al final  quan el Javascript hagi evolucionat prou, el  jQuery ja no serà necessari.

Però he de dir que jQuery força al programador a programar d’una manera elegant i ordenada. Tant de bo quan jQuery no faci falta es continuï utilitzant la mateixa elegància.

Vegeu més exemples a: https://css-tricks.com/now-ever-might-not-need-jquery/?utm_source=frontendfocus&utm_medium=email

jQuery:

var $elem = $(".someClass") //select the element 
$elem.remove(); //remove the element

Without jQuery:

var elem = document.querySelector(".someClass"); //select the element
elem.remove() //remove the element

 

jQuery:

$.ajax('https://some.url', {
  success: (data) => { /* do stuff with the data */ }
});

Without jQuery with  new fetch API is a superior replacement for XMLHttpRequest and is now supported by all modern browsers.

fetch('https://some.url')
  .then(response => response.json())
  .then(data => {
    // do stuff with the data
  });

 

 

 



No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>