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?
Skip it. It'd be confusing to the new users, anyhow. jQuery returns arrays of objects and applies function calls to each already, which isn't obvious to the noob. You'll spend time on each() and all you'll get from it is people who do $('a').each().css("color", "red");
or $('a').each(function(){ $(this).css("color", "red");});
Don't ask how I know noobs encountering .each() might end up making this mistake.
// changes every other div green
$("div").each(function(i) { if (i % 2) this.style.backgroundColor = "green"; });
Check all checkboxes in a datagrid based on the value of some external checkbox
$('#<%=dgMyDataGrid.ClientID %> :checkbox').each(function(i)
{
this.checked = $(#SelectAll).is(":checked")
});
I originally had a code behind findcontrol() method in place of the #SelectAll, but this hopefully illustrates what I was trying to do. This function was also bound to the click event of #SelectAll.
(also let it be noted that I am a jQuery newbie!)
edit: full implementation of what I used this for is here if anyone is interested :)