jQuery vs MooTools (1 vote for the former)

February 22nd, 2009

I spent the best part of the morning trying to figure out why a simple Ajax call with MooTools wouldn’t work correctly.

I was either getting no response and various script errors caught in FireBug, or jumping straight to the target URL, no Ajax happening.

I would have wasted more time trying to fix bugs in this had I not tried to do the same thing in jQuery.

With jQuery, it took me all of 1 minute to produce the desired result.

I haven’t really spent any time with JavaScript before and only hear from friends which framework they like best.

I’m sure for different things each has its own strengths, but I am adding a vote of confidence to jQuery!

Here’s the simple code to get a DIV replaced with the output of a PHP call:

inside html file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html>
 
<head>
 
<title>Your Page Title</title>
 
<script type="text/javascript" src="jquery.js"></script>
 
<script type="text/javascript">
function loadContent(elementSelector, sourceURL) 
{
	$(""+elementSelector+"").load(sourceURL+"");
}
</script>
 
</head>
 
<body>
 
<a href="javascript:loadContent('#content', 'your_script.php');">
Click to load content from PHP</a>
 
<div id="content">PHP output will be shown here</div>
 
</body>
 
</html>

This will replace the contents of the DIV with whatever is output normally by the PHP script.

You will need to download and add the jquery.js file to the same folder as this file. You will also need to put your php file in the same folder and run it all on a web server to see results.

To learn about running a test web server for free on your own computer, please browse my other posts, or just this one:

Running WordPress on MobileMe / dot Mac pt. deux