Hi Paul,

I may have misunderstood what you were going for, but here is a different approach, just in case you were looking for an array like ['abc', 'def', 'ghi']:

var txt = '', array1 = [];
$('ul:first li').each(function(i){
    txt = txt + $(this).html();
    if (i % 3 == 2) {
        array1.push(txt);
        txt = '';
    }
});


--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Feb 4, 2008, at 5:00 PM, Jonathan Sharp wrote:

Hi Paul,

This should do the trick:

$('li').each(function(i){
    array1[ Math.floor( i / 3 ) ] = $(this).html();
});

Cheers,
-Jonathan


On 2/4/08, Paul Jones <[EMAIL PROTECTED]> wrote:

I know the following would work if I wanted to copy the values of *each*
<li>
to a separate array element.

<html>
<head>
<title></title>

<script type = "text/javascript" src="jquery.js"></script>

<script type = "text/javascript">
var array1 = new Array() ;
$(document).ready(function()
{
$('li').each(function(i) {  array1[i] = this.innerHTML )  })
})
</script>

</head>

<body>

<ul>
   <li>a</li>
   <li>b</li>
   <li>c</li>

   <li>d</li>
   <li>e</li>
   <li>f</li>

   <li>g</li>
   <li>h</li>
   <li>i</li>
</ul>

</body>

</html>

However, I would like like to copy the *concatenated* values of each group
of
3 <li>'s to 1 array element.
(eg) the 1st array element would have a value of 'abc', the 2nd array
element would have a value of 'def', and the 3rd array element would have a
value of 'ghi' etc.

What is the best way to do this?

TIA


Reply via email to