[jQuery] low hanging newbie fruit for you to snack on
I've rewritten my site scripts with jquery and eliminated a bulky menu
script, 2 different image viewers, ajax/rpc script I did years ago,
and a bunch of other bits, now all packed down into about 26kb total
including jquery and with more functionality :-)
Some random newbie questions you hopefully can help with:
Is there a way to specify multiple conditions in one $ call or I must
do $("img.class").add("a.class"). Anything like $("img.class|
a.class")?
How much overhead is there in a $ object call on a single element? I
find myself avoiding jquery-wizz and using regular syntax unless I
really want to chain some things together, or need selectors.
Is a $ object cached, and calling it a few times in a function is
nothing? I would assume it checks if defined and if so there you go,
so same as using any regular variable?
var x = $(this.parentNode): is a pointer to a $ object a better way
when calling a few times, or a bad idea for memory leaks or anything?
Seem to recall leaks there.
Does the above x used as x.parent() et al entail as much overhead as a
whole new $ call to the parent ID itself, more, less? I'll have a
block where I need to get at several elements within it to change a
photo, description, etc.
Do the jquery traverse functions ignore white space and such that give
different results in moz/ie? If not, why not?
There is only 1 parent node so why does the api for parent() say "Get
a set of elements containing the unique parents of the matched set of
elements." And have an option to filter the parent set returned.
Does the ajax timeout call the error function? Api doesn't say. If
not, why not and how to call a function from a timeout?
Is it possible to put an element reference into an ajax call that is
then used/returned in a success/error function? I've had to set a
variable above the ajax function ( x=$(this); ) that gets used in the
success/errors because "this" is no longer "that" within them :-)
It appears ajax does not account for caching by attaching a time
variable to url's as an option for GETs. Why not? Or did I miss it?
preventDefault and stopPropagation work xbrowser in jquery, correct?
They don't get much mention in the api except under one item, and I
always see plugins using "return false" instead.
How would you recommend doing doc ready calls that are only needed on
some pages of the site? It's such a waste if not needed. I'm worried
if I stick the call on the indiv. pages perhaps the jquery js file has
not loaded before it gets there - or does ext js have to be loaded and
parsed as arrived at? I think maybe that's only inline js, no? Maybe a
2nd external file on the specific page to call it? Or perhaps plugins
in the jquery file, called from the specific page, are the best way to
go?
For now I've wrapped the onready calls in an if createElement but that
doesn't help for specific bugs. Are there plans to detail exactly what
calls are failing in jquery in different browsers because I can't see
what might trigger a problem in a particular browser, what needs to be
avoided, protected, etc. This really is lacking and needs to be
documented clearly. Plans? I'm aware of http://docs.jquery.com/Known_Issues
but only one point is noted there!
Thanks. Hope some of you jquery pros enjoy the low hanging fruit
above :-)