Maybe I can help until someone who actually knows what they're talking about replies :)
On 4/3/07, stylo~ < [EMAIL PROTECTED]> wrote:
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")?
I am not exactly clear on what you're after here, but as far as selecting you of course have many options and methods available. You could get all 'top-level' items at first, and then filter out as needed, using end() to transition: $('a').filter('.foo').hide().end(/* should return us to the $('a') result now */).filter('.bar').show(); Would be the same as: $('a.foo').hide(); $('a.bar ').show(); Or, you could also do like so: $('.foo, .bar', 'a').hide(); Would be the same as: $('a.foo').hide(); $('a.bar').hide(); 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.
I believe it was John who said the following (my apologies if not): The "speed hierarchy" goes like this, in order of fastest to slowest: 1. ID : $('#some-id') 2. Element : $('div') 3. Class : $('.some-class') So basically, calling $() on a single object via ID is the most efficient. 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?
Somewhat unclear on this one also, although note that if you are going to reuse a query you should cache it locally, i.e.: var foo = $('.foo'); foo.hide(); // do stuff foo.show(); // do stuff foo.hdie(); // etc. That would be more efficient than calling $('.foo') for each operation. 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.
See above? 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.
If I understand correctly, you should also try to cache a result if you are going to use it more than once. Every call to $() requires extra processing. Sorry but I have to go for now- hopefully someone will correct my mistakes and fill in the rest of the blanks for you :) 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 :-)