Just learning Java Script & JQuery, but an experienced developer, I've created a page with a series of elements that use the .slideDown() and .slideUp() functions to reveal and hide the different areas of content on the page.
To facilitate this, the page's html uses links with ids similar to: { "dataRevealLink1", "dataToReveal1", "dataHideLink1" }. Clicking on a "data-reveal-link" causes a .slideDown() animation on "data to reveal", with appropriate reverse logic attached for the data hiding as well. The page in question has 12 such sections, and writing the script long form (no loops) works fine. However, I would like to generalize this logic, but my first attempt at a loop to attach the DOM element callbacks does not work, and I suspect it's a scoping issue with java script: for (var i = 1; i <= 12; i++) { var eventElem = "#dataRevealLink" + i; var actOnElem = "#dataToReveal" + i; $(eventElem).click( function() {    $(actOnElem).slideDown();    return false; // prevents the link from processing this click   }); } I suspect that in the above logic, the mouse-click callback is attaching to the dataRevealLink1-12 fine, however once inside the callback, "actOnElem" is not what I'm expecting - possibly due to the scope of actOnElem? I'm not entirely sure... I've added console.log() calls to the above logic, and everything is as I expect during the above looping, but I am never getting any of the callbacks to run, so I can never see any console.log() output from inside a mouse-click handler... Any advice anyone? -- View this message in context: http://www.nabble.com/JQuery-events-and-a-possible-scoping-error-on-my-part--tp24330608s27240p24330608.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.