That's a rather big basket of "low hanging fruit" you've got there.
You should really read the source, if you have the time.
Inline replies below.
On 4/3/07, stylo~ <[EMAIL PROTECTED]> wrote:
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")?
jQuery selectors are CSS (or XPath) based so, just like in CSS you can
"select" more than on class by using ",". To use your example:
$("img.class").add("a.class")
Becomes:
$("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.
The "overhead" is mainly a time one, and that depends on the selectors
you use. What you're doing now is perfectly fine.
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?
The $ (or jQuery) function/constructor is not cached (as far as I'm
aware). In many cases that would not make sense. Consider if you
select $('div.section') then add a whole bunch of new "div.section"s
dynamically, you'd want the new list rather than the old.
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.
You should be able to safely store that without leaking. jQuery goes
out of it's way to make sure that it won't "leak". I believe there are
a few minor leaks that are being worked on at the moment but in most
cases it won't cause you grief.
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.
Not quite sure what you mean here. With reguard to overhead, if you
don't need the selection system or the chaining then it is usually
faster to call the "native" functions.
Do the jquery traverse functions ignore white space and such that give
different results in moz/ie? If not, why not?
Yes, the "traversal" functions (next(), prev()) ignore text and white
space nodes, consistantly across browsers.
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.
Because you can call parent() on a group of selected items. For
example given the following HTML:
<ul>
<li>1</li>
<li>2</li>
</ul>
<ul>
<li>A</li>
<li>B</li>
</ul>
Calling:
$('li').parent();
Would return a jQuery object containing both UL elements.
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?
Don't know. This is not my strong point. Someone else can answer this.
Or better yet, try it out yourself :).
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 :-)
As far as I know, for the ajax functions, the method you're using is
the way to go.
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?
:) Because sometimes you want the URL to be cached. jQuery is a
library (an a "thin" one at that) rather than a framework, so it tries
not to have features you need to work-around.
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.
That's correct. Returning false from inside an event handler will do
the appropriate preventDefault and stopPropagation function calls for
the browser.
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?
Script tags are processed in order and the next script tag isn't
"executed" until the the current one is loaded and "executed". Most of
the time that little extra time it takes to load jquery.js won't cause
you any problems. I hope that covers your concerns.
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!
Again not something I'm too familiar (or worried) about.
I build most my stuff for newer browsers and with "progressive
enhancement" in mind. Unless you need to support IE < 6.0 or some of
the older Netscapes, it shouldn't be too much of an issue.
Thanks. Hope some of you jquery pros enjoy the low hanging fruit
above :-)
That was quite a fruit basket. :)
Karl Rudd