It is not JQuery syntax. There is no such thing as JQuery syntax (nor
Prototype syntax), the code is javascript and so must use javascript
syntax. The code may be calling JQuery functions and methods, but then
it may also be calling the functions and methods of code that is (by
coincidence or imitation) indistinguishable from JQuery in the
external appearance of the functions/methods used above.
You can be intentionally obtuse and argumentative all you want, but
that doesn't actually help anyone.
The example syntax most closely resembles jQuery, from my experience.
And since the code snippet comes directly from a presentation by John
Resig, author of jQuery, the original poster would probably be most
interested in checking out jquery.com.
Similarly, if anyone was asking about code like
var panel_one = new YAHOO.widget.Panel("panel_one", {} );
it would be logical to point them to YUI, although the code isn't
necessarily from YUI.
And just for fun, I'll give more info on the code:
This command takes a function as an argument, to be executed when the
DOM is ready to be manipulated, but before window.onload is fired.
This is the beginning of an anonymous function which is the argument
to ready()
$("li").behavior("click",
The $() function, in jQuery and many other libraries, is a selector.
It's argument is typically a CSS selector used to identify elements in
a page which will then be somehow manipulated. In this case, $("li")
will select all "li" elements in the page.
The .behavior syntax isn't something I recognize, but maybe was
included as an example of behavior-driven syntax. In jQuery, you would
typically just write .click(function) which would specify a function
to fire when the "onclick" event is fired.
So this line is attaching a function to be execute onclick of all LI
elements in the page.
function(){
$(this).load("menu.html");
}
This is the function that will be fired when an LI is clicked.
In this example, 'this' will be a reference to the element itself, and
passing it to the $() function just selects it and makes the jQuery
functions available.
In this case, .load() is called which is an AJAX shortcut to load the
specified file and replace the inner content of the selected element
with the content returned from the AJAX call.
And those are there to close everything off.
Sometimes the over-abundance of $(){} and anonymous functions can make
this style of development a bit cryptic. It helps to format the
source. I also add some layers on top of this syntax to avoid so many
anonymous functions, etc. This certainly is only one way to develop
javascript, and other libraries and reusable code use entirely
different approaches. Pick the one that makes sense to you, or none at
all
Matt Kruse