Prototype and jQuery : A code comparison

Pubblicato da lentux-informatica il

  •  
  •  
  •  
  •  
  •  

The two biggest JavaScript frameworks in use are jQuery and Prototype.

Until recently, I used Prototype a bit.

After having to use jQuery for a recent project, I’ve actually started to enjoy using it.




It’s easy to use, and it’s lightweight. I’m probably going to re-code a bunch of things over at NTugo so I can use jQuery there instead of Prototype.

It’s a lot better.

Enough of my personal experiences, here are the hard facts:

JQuery

Code Required to Toggle a DIV:

 

<script type="text/javascript">
$('#mydivtrigger').click(function() {
$('#mydiv').toggle(400);
return false;
});
</script>
<a href="#" id="mydivtrigger">Toggle!</a>
<div id="mydiv">
</div>


Approfitta di tutte le offerte di Amazon per i tuoi regali di Natale con sconti fino al 60% su moltissimi prodotti!!!


Prototype

Code Required to Toggle a DIV:
 
<script type="text/javascript">
function toggleMyDiv() {
Effect.toggle('mydiv','slide');
return false;
}
</script>
<a href="#" id="mydivtrigger" onClick="toggleMyDiv()">Toggle!</a>
<div id="mydiv">
</div>

The amount of code is similar, though Prototype requires an onClick event handler.

The presentation looks into the utility functions, selectors, DOM manipulation, DOM walking, events, Ajax transport, and browser detection.

Now you can choose beetwen jQuery and Prototype.


  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •