Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #12969

Re: nest an each loop within an each loop??

From Gregor Kofler <usenet@gregorkofler.com>
Newsgroups comp.lang.javascript
Subject Re: nest an each loop within an each loop??
Date 2012-03-21 23:24 +0100
Organization A noiseless patient Spider
Message-ID <jkdkek$vuh$1@dont-email.me> (permalink)
References <7ad2b63a-d265-4b4b-80f0-11a5bcced32e@w5g2000vbv.googlegroups.com> <344341f8-90b2-44e5-9f9c-0b4af8828c52@w5g2000vbv.googlegroups.com>

Show all headers | View raw


Am 2012-03-21 19:47, tommls meinte:

>> jQuery(function($){
>>   $('#myCarousel img').each(function(index) {
>>     var imgWidth=$('#myCarousel img').width();
>>     alert(imgWidth);
>>     $this = $(this).wrap('<div class="img-caption" style="width:' +
>> imgWidth + 'px; float:left;" />');
>>     $('<p>' + $this.attr("title") + '</p>').insertAfter($this);
>> });
>> });
>>

Ah, beautiful code abound.

> Basically any kind of code which will look through all the images and
> apply the above code depending on the image's ID (or class if
> necessary).

Something like

var img = document.images, l = img.length;

while(l--) {
  if(img[l].className == "whatever") {
    ...
  }
  else {
    ...
  }
}

I can only guess what your "above code" does, since I don't do jQuery,
your coding style is horrible [1], and the snippet is anything but ligible.

[1]
Constructs like
$('#myCarousel img').each(function(index) {
  var imgWidth=$('#myCarousel('img').width();
[..]
look like /slight/ overhead, even for a non-jQuery ninja.


Gregor


-- 
http://vxweb.net

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

nest an each loop within an each loop?? tommls <tlyczko@gmail.com> - 2012-03-21 11:26 -0700
  Re: nest an each loop within an each loop?? tommls <tlyczko@gmail.com> - 2012-03-21 11:47 -0700
    Re: nest an each loop within an each loop?? Gregor Kofler <usenet@gregorkofler.com> - 2012-03-21 23:24 +0100
  Re: nest an each loop within an each loop?? SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-03-22 00:58 +0100

csiph-web