I want to loop through a set of <a>'s in an unordered list.
In jQuery, I'd do it this way:
$("#list ul li a").each(function (x) {
// Do Stuff
});
It's probably a simple question, but how do I pass a variable through as that id shown in the function there? I'd imagine it is something like:
var myVar = 'foo';
$("#list ul li a").each(myVar, function (x) {
// Do Stuff
console.log(x);
});
Console out: foo.
But that doesnt seem to work, how do I do this?
.each()can "see" local variables like "myVar" in the surrounding code. What is it that you want to do exactly?console.log(myVar)in theeach()would work fine, though.