The way that jQuery works is NOT the same way that JavaScript works, even though they are one and the same. jQuery works on CSS selectors, like the class name(s) and the id of elements. To select an item in jQuery, you do:
$("#yourID") or $(".yourClass") or $("div") or $("#yourID p") etc
And you will get a collection of all the elements on the page that fit your criteria. You can then perform your actions on ALL of those elements without any looping of any sort. This is important to remember:
$(".yourClass").click(function(){
//do stuff
});
will affect all items with .yourClass
attached to them. One tip: if you're going to access the $(this)
, you should save it as a local variable:
$(".yourClass").click(function(){
var $this = $(this);
});
as it will speed up your function.