If you want to do this using JavaScript I would suggest using an array, and
iterating through it. This way you can simply increment or decrement the
index. However, unless it is critical that this be done client-side, I would
suggest that you do it server-side so that you can avoid unnecessary messy
JavaScript (I am a fan of JavaScript, but if it does not improve the
appearance, performance, or usability of a page, I prefer server-side). If
it is critical and you need help creating the script, let me know. Good
Luck!

Signature
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/
>I need to write a script that will reverse the ordering of the <span> tags
>programatically.
[quoted text clipped - 14 lines]
>
> Can this be done with javascript? Sorry I'm new to programming.
Tem - 13 Oct 2007 19:51 GMT
I thought of that too but I want to save users from redownloading the page.
Here's my thinking
Get all objectsin paragraph
Save objectsin to an array
Reverse the array
Push the objectsin back to paragraph
if you can help me translate this into javascript that would be great
thanks
> If you want to do this using JavaScript I would suggest using an array,
> and iterating through it. This way you can simply increment or decrement
[quoted text clipped - 22 lines]
>>
>> Can this be done with javascript? Sorry I'm new to programming.
Nathan Sokalski - 13 Oct 2007 21:37 GMT
Try this:
<div id="divParagraph" class="paragraph">
<span class="line">line 1</span>
<span class="line">line 2</span>
<span class="line">line 3</span>
</div>
var lines[];
var index=0;
var original=document.getElementById('divParagraph').innerHtml;
var index1=original.indexOf('<span');
var index2=original.indexOf('<span',index1+1);
while(index2!=-1)
{
lines[index]=original.slice(index1,index2-1);
index1=original.indexOf('<span',index1+1);
index2=original.indexOf('<span',index2+1);
index++;
}
lines[index]=original.slice(original.lastIndexOf('<span'),original.length-1);
document.getElementById('divParagraph').innerHtml='';
for(line in lines)
{
Alexey Smirnov - 13 Oct 2007 21:47 GMT
> I thought of that too but I want to save users from redownloading the page.
>
[quoted text clipped - 7 lines]
> if you can help me translate this into javascript that would be great
> thanks
Tem, you can also create an array from the beginning and use it to
populate a paragraph and then to sort an elements...
<script>
function cloneNodeList(list)
{
var a = new Array();
for (var i=0; i < list.length; ++i)
a[i] = list[i];
return a;
}
function reverseDiv()
{
var div = document.getElementById('foo');
var spans = cloneNodeList(div.childNodes);
for (var i=0; i < spans.length; ++i)
div.removeChild(spans[i]);
for (var i=spans.length-1; i >= 0; --i)
div.appendChild(spans[i]);
}
</script>
<div class="paragraph" id="foo" onclick="reverseDiv();">
<span class="line">line 1</span>
<span class="line">line 2</span>
<span class="line">line 3</span>
</div>
-- bruce (sqlwork.com)
> I need to write a script that will reverse the ordering of the <span>
> tags programatically.
[quoted text clipped - 14 lines]
>
> Can this be done with javascript? Sorry I'm new to programming.
Tem - 14 Oct 2007 01:04 GMT
Thank you
> <script>
> function cloneNodeList(list)
[quoted text clipped - 40 lines]
>>
>> Can this be done with javascript? Sorry I'm new to programming.