each

How can I dynamically override a class's "each" method in Groovy?

Groovy adds each() and a number of other methods to java.lang.Object. I can't figure out how to use the Groovy metaclass to dynamically replace the default each() on a Java class. I can see how to add new methods: MyJavaClass.metaClass.myNewMethod = { closure -> /* custom logic */ } new MyJavaClass().myNewMethod { item -> println item ...

Grab only 2 items from Jquery Loop

Here is my Jquery $th.each(function(idx) { var notSelected = $(this).text(); if ((notSelected.indexOf(to) != -1) || (notSelected.indexOf(from) != -1)) { if (idx < 10) { $(this).show(); // and show its corresponding td $td.eq(idx).show(); } } }); It is part of a table...

.each or search function, how can I make use of those?

I have a ul list, with 10 items, and I have a label that displays the selected li text. When I click a button, I need to check the label, versus all the list items to find the matching one, when it finds that I need to assign the corresponding number. I.e. list: Messi Cristiano Zlatan hidden values of list items: www.messi.com www.cr...

How to exit mootools each()

How can I exit the each function when the conditions was true once? This does not work: $$('.box div').each(function(e) { if(e.get('html') == '') { e.set('html', 'test'); exit; } }); ...

jQuery each loop - using variables

I have a list of products. Each product has a title and a review link. Currently the titles link directly to the individual product page, and the review links go elsewhere. I'd like to use a jquery each loop to cycle through each li, take the href from the title (the first link), and apply it to the review link (the second link), so th...

JQuery Each setInterval Repeat Problem

I'm using a set interval function with jQuery to loop through a list of times on a calendar so that the individual divs can be refreshed. First I put this code on a page that was called via Ajax, but the function would never receive the new date variable set. It would just recognize the variable it saw when the page was first loaded. Th...

JQuery each loop problem

Hello, I have the following code <div> <a href="#" class="clickMe">test</a> <ul> <li class="action_li">1</li> <li class="action_li">2</li> </ul></div> <div> <a href="#" class="clickMe">test</a> <ul> <li class="action_li">3</li> <li class="action_li">4</li> </ul> and I want to loop on all the <li> that ar...

Overriding form submit based on counting elements with jquery.each

I am probably going about this all wrong, but here's what I'm trying to do: I have a form that has approximately 50 select boxes that are generated dynamically based on some database info. I do not have control over the IDs of the text boxes, but I can add a class to each of them. Before the form is submitted, the user needs to select a...

Jquery, ajax() and each(), how to wait untill all info is really loaded?

Hello, I have a function using $.ajax() to get values from an XML file, when the info is loaded and success event is fired, I use $(xml).find('').each(function(){}); to populate some vars... function getData() { $.ajax({ type: 'GET', url : 'info.xml', dataType: 'xml', success: function(xml) { ...

jQuery .each() with Array

Basically, I am trying to gather the IDs of every element with a specific class and place those IDs into an array. I'm using jQuery 1.4.1 and have tried using .each(), but don't really understand it or how to pass the array out of the function. $('a#submitarray').click(function(){ var datearray = new Array(); $('.selected').e...

jquery :first selector loop problem

$(".wrap table tr:first").addClass("tr-top"); it works for the first table, but i have many tables under the div .wrap. what should i do? thanks! ...

Jquery each loop with json array

I'm trying to use Jquery's each loop to go through this JSON and add it to a div named #contentHere. The Json is as follows: { "justIn": [ { "textId": "123", "text": "Hello", "textType": "Greeting" }, { "textId": "514", "text":"What's up?", "textType": "Question" }, { "textId": "122", "text":"Come over here", "textType": "Order" }...

Calculating total width of all list items?

Hi There, I have a standard UL as follows: <ul> <li><a href="">Link</a></li> <li><a href="">Link</a></li> <li><a href="">Link</a></li> <li><a href="">Link</a></li> <li><a href="">Link</a></li> </ul> I am trying to find a quick & efficient way to calculate the combined with of all the LI tags. Currently I have: var width = ...

JQuery .each() and IE all versions problem

i am using this code and it is working on all browsers without a glitch but with IE all versions it`s not working can anyone help me with this $('a.download').each(function() { $(this).colorbox({href:$(this).attr('href') + ' div#download_popup',onComplete: function(){ $('div.sociable').hide(); $('a#share_button').click( fun...

each function jquery. is it correct??

$('.dragbox').each(function(){ $('.close').click(function(){ $(this).parent().hide(); }), $('.colpase').click(function(){ $(this).siblings('.dragbox_content').toggle(); }) }); ...

Grails/GSP: break out of <g:each>

Is there a way to break out of a <g:each>? I have a page wherein I'm iterating through a list and I have to make sure that a checkbox is checked if that was the value stored in DB. To make it a little clearer, please consider something like: <g:each in=${list1}> <g:each in=${list2}> <g:if test="${list1.id == list2.id}"> ...

Nested Each Loop Causing Problem

Hello – My question is best summarize with the intended output and the real output. Any clue why it's doing this, using the following HTML and JS code? HTML Code: <h3>CATEGORY 1</h3> <p>Item 1</p> <p>Item 2</p> <h3>CATEGORY 2</h3> <p>Item 3</p> <p>Item 4</p> <h3>CATEGORY 3</h3> <p>Item 5</p> <p>Item 6</p> JavaScript / jQuery Code:...

How to make this trick with Jquery's each?

My php code: for($i = 1; $i < 22; $i++) { echo '<div id="number" style="display:none">'.$i.'</div>'; } My jquery code: $('#number').each(function() { $(this).slideDown("slow"); }) What's wrong here? I want to achieve effect when all numbers, each after another would appear. I mean, first of all slides down number 1, ...

Nested jQuery.each() - continue/break

Consider the following code: var sentences = [ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'Vivamus aliquet nisl quis velit ornare tempor.', 'Cras sit amet neque ante, eu ultrices est.', 'Integer id lectus id nunc venenatis gravida nec eget dolor.', 'Suspendisse imperdiet turpi...

for vs each in Ruby

I just had a quick question regarding loops in Ruby. Is there a difference between these two ways of iterating through a collection? # way 1 @collection.each do |item| # do whatever end # way 2 for item in @collection # do whatever end Just wondering if these are exactly the same or if maybe there's a subtle difference (possibly ...