each

What's the safest way to iterate through the keys of a Perl hash?

If I have a Perl hash with a bunch of (key, value) pairs, what is the preferred method of iterating through all the keys? I have heard that using each may in some way have unintended side effects. So, is that true, and is one of the two following methods best, or is there a better way? # Method 1 while (my ($key, $value) = each(%hash)...

Perl: while ($key = each %hash) doesn't stop at key = 0

I don't need this, obviously; I'm just curious about what's going on here. Am I missing something simple? Can I rely on this behaviour in all versions of Perl?) Perl v5.8.8: %h = ( 0=>'zero', 1=>'one', 2=>'two' ); while ($k = each %h) { $v = delete $h{$k}; print "deleted $v; remaining: @h{0..2}\n"; } outputs deleted one; rem...

How do you find the last loop in a For Each (VB.NET)?

How can I determine if I'm in the final loop of a For Each statement in VB.NET? ...

JQuery - How to add a class to every last list item?

Howdy Guys, Got some code here that isn't working: $("#sidebar ul li:last").each(function(){ $(this).addClass("last"); }); Basically I have 3 lists and want to add a class (last) to each item appearing last in each unordered list. <ul> <li>Item 1</li> <li>Item 2</li> <li class="last">Item 3</li> </ul> Hope ...

Problem selecting class using jquery

Hi everyone, I've been banging my head against a wall trying make this work for a while now. I'm trying to shorten the comment body to one line for compact comment preview. I'm using jquery .each function to go through each .cbody (comment body) in my threaded comment system and place it in the cshort div inside chead. It should work but...

The difference between assigning event handlers with bind() and each() in jQuery?

Hi, can someone tell me what the difference between assigning event handlers using bind(): $(function(){ $('someElement') .bind('mouseover',function(e) { $(this).css({ //change color }); }) .bind('mouseout',function(e) { $(this).css({ //return to previous state }); ...

jQuery loop through data() object

Is it possible to loop through a data() object? Suppose this is my code: $('#mydiv').data('bar','lorem'); $('#mydiv').data('foo','ipsum'); $('#mydiv').data('cam','dolores'); How do I loop through this? Can each() be used for this? ...

Jquery width() through iteration?

I'm having a bit of trouble iterating and retrieving width() values. $(".MyClass").each( function(){ elemWidth=$(this).width(); } ); so for each "MyClass" element i would like to find the width (some are different). But the above code only produces the width() of the first instance of MyClass and returns 0's after that. Any ...

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

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? ...

[jQuery] How do i get the value of all other dropdowns when one of them is changed.

Hello Everyone, I am trying to populate a text box based on the values from a set of dropdowns. Once the user changes the value of a dropdown, I would like to get the values of all other dropdowns that are contained within the same div. In the example below, I am trying to display the value all 'selects' in a gien div through a dialo...

JQuery: Access original jquery object within each

I'm trying to implement HTML radio button behaviour on a set of DIVs in JQuery. I want to remove the "set" class from all the elements then use addClass() to re-set the (one) element that is clicked: $(".button").each(function() { $(this).click(function(){ // what goes here to call removeClass() on *all* the elements? $(this)....

Another jQuery noob question about functions

I want to "functionalize" more of my jQuery code, instead of writing little standalone snippets. Here's an example. Let's say I have some li's that I'd like to use as triggers, like so: <li class="alpha-init" id="a-init">A</li> <li class="alpha-init" id="b-init">B</li> <li class="alpha-init" id="c-init">C</li> And some stuff I'd like ...

jQuery .attr function not returning correctly

I am building a list with checkboxes, after the list is created I am using ".each" to go through them all and trying to apply a click procedure. My code like this works fine: $.ajax({ url: "./views/todoitems.view.php", data: "cmd=list", success: function(html){ $('#list-container').empty().append(html); $('input:checkbox').each(...

setTimeout inside $.each()

ok, so I've got this code: $(this).find('article.loading').each( function(i) { var el = this; setTimeout(function () { $(el).replaceWith($('#dumpster article:first')); }, speed); }); I want to replace each element with another but I want a delay between each replace. I can't figure out why this isn't working...

Using jQuery each to grab image height

I have a bunch of images on a page. I'm trying to use jQuery to grab the height of each image and display it after the image. So here is my code: $(document).ready(function() { $(".thumb").each(function() { imageWidth = $(".thumb img").attr("width"); $(this).after(imageWidth); }); }); <div class="thumb"><img src="" borde...

jQuery - .each() returning only the first element attributes, need to store each element attribute and use in each child element

I'm having headaches trying to make this work: I have a <a> element with a background-image defined with style="" attribute and I have put a function to append inside the <a> element a <span> handling different background-positions for :hover effects with opacity changes. The thing is, I need to get the same style attribute from each <a>...

equivalent of each() for mysql results, to mimic first loop of foreach()

Hi, I've seen in the code I'm working on, the following: foreach( $mysql_result as $row ) $site_id = $row->id; $mysql_result is, of course a mysql_result, so this foreach is equivalent to a while( mysql_fetch_row() ) Sometimes, the result is known to yield only one row, but the code still has a "foreach" so it gives the impression of ...

JQuery .each() callback function doesn't run on each iteration/loop

Here's what should happen. 1. Get the rel attribute of the clicked link 2. For every div with class 'entry': (i)Get its 'left' position (ii) Calculate its outer height (iii)Loop through all instances of 'a.tag_filter'. If it finds the same string in the 'rel' as the one oringinally clicked on then add 1 to 'V' and break out o...

jquery each function and queue

i have an array: arr = ['a', 'b', 'c', ... ] i want it to be: <div> <ul> <li>a <li>b <li>c ... </ul> </div> so i'm trying: $('div').append('<ul>'); $.each(arr, function () { $('div').append('<li>' + this); }); $('div').append('</ul>'); but doesn't seem working... how can i queue this? ...

Replacing jquery each with for

I apologize in advance if this is a stupid question that betrays my lack of understanding of javascript/programming. I've been using $.each to do iterations for a while now, but I keep on hearing people say to use native JS for to do loops. I'm very concerned about performance but I am not sure if it's always possible to replace $.each...