williamrouse Posted February 3, 2010 Report Share Posted February 3, 2010 Home Mission Projects How to Help Donations Supporters News Contact Quote Link to comment Share on other sites More sharing options...
williamrouse Posted February 4, 2010 Author Report Share Posted February 4, 2010 I resolved the issue. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 4, 2010 Report Share Posted February 4, 2010 You mind sharing the solution, in case others run into the same thing? Quote Link to comment Share on other sites More sharing options...
williamrouse Posted February 4, 2010 Author Report Share Posted February 4, 2010 Sorry about that! Given the above structure of the div: $(document).ready(function() { // put all your jQuery goodness in here. $('#mainMenu a').click(function(){ var $target = $(this).attr('id'); var $number = $(this).index('a'); $number++; $("#response").text("Menu choice '" + $target + "' was chosen, OK! " ); $('#response').append(' That is item "' + $number + '".'); }); }); Quote Link to comment Share on other sites More sharing options...
williamrouse Posted February 4, 2010 Author Report Share Posted February 4, 2010 I should add that I am working on a phrase like this: $chosen = $('mainMenu a').click(function(){ }); And then get all the values from $chosen. Quote Link to comment Share on other sites More sharing options...
BeeDev Posted February 4, 2010 Report Share Posted February 4, 2010 It might work your way but I usually do it in the following syntax : $(document).ready(function() { // put all your jQuery goodness in here. $('#mainMenu a').click(function(){ var $target = $(this).attr('id'); var $number = $("a").index(this); $number++; $("#response").text("Menu choice '" + $target + "' was chosen, OK! " ); $('#response').append(' That is item "' + $number + '".'); }); }); Quote Link to comment Share on other sites More sharing options...
williamrouse Posted February 4, 2010 Author Report Share Posted February 4, 2010 BeeDev: I'm not sure of your usage of "might" since it consistently works with the limited testing I have done. I wanted to ask though if you have been able to find your way through a returned object as I was trying to do too further understand JavaScript and jQuery. Here is what I mean more clearly, I hope: $chosen = $('mainMenu a').click(function(){ }); Have you ever used that construct and then grab the ID name and index from the returned object? Thanks now! WBR Quote Link to comment Share on other sites More sharing options...
BeeDev Posted February 5, 2010 Report Share Posted February 5, 2010 (edited) Not really, you need to be inside some context to use index() because you need "this" to index something. What are you trying to do? Maybe I know a different way to do it. Have you looked at .each() method? You can do counters & stuff with it easily: $("mainMenu a").each(function(counter){ $(this).bind("click",function(){ //you can use variable 'counter' here to program stuff like: $("#content div").eq(counter).show(); //so when 4th link in main menu is clicked - the above script will show the 4th div inside element with id #content }); }); Edited February 5, 2010 by BeeDev Quote Link to comment Share on other sites More sharing options...
williamrouse Posted February 5, 2010 Author Report Share Posted February 5, 2010 Mostly study and exploration since I got the task done I was asked to do. I spent over an hour yesterday with firebug looking at the returned object data structure and found out you are correct there is nothing in there to use. Quote Link to comment Share on other sites More sharing options...
williamrouse Posted February 5, 2010 Author Report Share Posted February 5, 2010 BeeDev: In the example code you wrote above. I don't understand what you are trying to show me. Could you flush it out more and/or show me more of some example code. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.