[jQuery] best practices / using jquery in functions
hello all-
I'm new to jquery, and a novice javascript coder with a basic working
knowledge of OOP from java. I'm trying to create some animated boxes
for a client page- right now, i have a basic motion test with
placeholders just to see how this would work here:
http://inforetail.com/motiontest/
You can look at the page to see the BASE behavior I'm looking for.
And If you take a look at the code, it's nasty- I've got a series of
statements tied to custom click events for each link, which act on
each box accordingly.
Ideally, I'd like to genericize this so that the action of opening
one box and closing the others is as simple as possible; I see two
ways to do this:
1. Using a combination of the "this" statement and whatever parental
transversal techniques I would need to automatically identify the
enclosing box, and then then do the rest... but I'm quite unclear on
using "this", and not sure of the best way to have a set of functions
that run on both the parent and various other children of that parent.
2. Write my own function that gets tied to the onclick even in the
html, that passes in the enclosing div name, i.e. onclick="divOpen
(homeIR);" and pass that along to the requisite jquery statements
within the function. But again, not sure the best way to identify
the other divs. My other concern with this method is specifying and
calling it from the HTML... is this less accessible or otherwise a
compromise from being able to trigger the event from within the
document.ready function like I am now?
or maybe some combination thereof.
Also, some related questions:
1. is my best way to control order of operations (i.e. CLOSE the
other Div BEFORE you open the one that is clicked) using the callback
portion of a function?
2. ultimately, just like my fading image now, I may have a number of
fades and other actions on children of the opening and closing DIVs
that would get built into this. Does that change the answer to my
main question?
3. Obviously, there may be a far more elegant way to do all of this -
if I'm barking up the wrong tree, just say so. :)
Thanks in advance for any light you can shed on this...
best,
Brendon
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/