Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Practical Uses for jQuery's $().each() method for a presentation

Tags:

jquery

loops

each

I'm giving a presentation to some coworkers today on how to use jQuery with ColdFusion. This is more of an introduction to jQuery than an advanced session. I'm trying to show how one can loop using jQuery's $().each() method, and in trying to come up with some practical, real world examples and I've drawn a blank. Any suggestions?

like image 546
Hooray Im Helping Avatar asked May 14 '09 12:05

Hooray Im Helping


People also ask

What does $( this represent with each method?

$(this) is just used to wraps the DOMElement in a jQuery object so you can apply jQuery method on this .

What does each mean in jQuery?

each(), which is used to iterate, exclusively, over a jQuery object. The $. each() function can be used to iterate over any collection, whether it is an object or an array. In the case of an array, the callback is passed an array index and a corresponding array value each time.


1 Answers

// changes every other div green
$("div").each(function(i) { if (i % 2) this.style.backgroundColor = "green"; });
like image 104
Matt Briggs Avatar answered Oct 20 '22 17:10

Matt Briggs