functions, nesting and calling
Hi, I'm a super newbie, having been working at jquery for about two days now.
I have a question regarding the nesting and calling of functions. I'll attempt to paint it in a fairly simple way.
I have a page that offers the user a few choices (its a game, so..) like attack or defend, what weapon to use. It then loads two html <select>'s, each with a "commit" button. The commit buttons are tied to (separate) functions that pass data to ajax.
The problem I have is that I'm getting buried in nested functions. Does that make sense? My code looks something like this:
- $(function() {
- $('#choice1').click(function() {
- //do some stuff
- });
- $('#choice2').click(function() {
- //do some stuff
- });
- $('#choice3').click(function() {
- //do some stuff, including creating the choices below, and their submit boxes
- $('#subChoice1').click(function() {
- //do some stuff
- //now I need to go back to some kind of a nextFunction
- });
- $('#subChoice2').click(function() {
- //do some stuff
- //now I need to go back to some kind of a nextFunction
- });
- }); // end choice3
- });
When I get down to subChoice1 and 2, I don't seem to be able to just call upon another function unless it is nested beneath itself.
I hope that makes sense.
Any pointers to get me headed in the right direction? I'm hoping that there is a simple answer that I just haven't discovered yet.
Thanks!