I’m going to be writing a callable function which will make use of jQuery. But I can’t find any reference to ordinary function declaration with jQuery; it’s all about element manipulation functions. Can I essentially just declare an ordinary javascript function and then use jQuery in it, or do I need to be doing something special? Is this okay?
function useJQ(xml)
{
var groups = {};
$('resultGroups', $(xml)).each(function() {
var count = $('results', this).length;
var name = $('name',this).text();
groups[name] = count;
}
You need not extend jQuery to do such tasks. You can use plain functions to do what you need to do. just ensure that you don’t pollute the global namespace by setting your own namespace.
However, if just want to use the jQuery namespace instead of your own, here’s a quick way to add them:
the effect is like: