Not able to access alternative elements using DOM
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kiran_Gopalakrishnan
Posted On:   Thursday, July 14, 2005 05:11 PM

This is the 'for' loop that I am using to remove rows from one table and add append them to another table, depending on the className. i.e.: if the className is ''clsTableTextHighlight'' then, remove that row from the first table and add it as a child to the new table. Please note that 'source' and 'target' are passed as parameters and are table ids. for(var i=1; i <=document.getElementById(source).firstChild.childNodes.length; i++) { var currSourceRow=document.getElementById(source).firstChild.childNodes[i]; if(currSourceRow.className=='clsTableTextHighlight') { var targetNode=document.getElementById(target).firstChild; var newNode=currSourceRow.cloneNode(true); ne   More>>

This is the 'for' loop that I am using to remove rows from one table and add append them to another table, depending on the className. i.e.: if the className is ''clsTableTextHighlight'' then, remove that row from the first table and add it as a child to the new table.

Please note that 'source' and 'target' are passed as parameters and are table ids.

			
for(var i=1; i <=document.getElementById(source).firstChild.childNodes.length; i++)
{
var currSourceRow=document.getElementById(source).firstChild.childNodes[i];
if(currSourceRow.className=='clsTableTextHighlight')
{
var targetNode=document.getElementById(target).firstChild;
var newNode=currSourceRow.cloneNode(true);
newNode.className='clsTableText';
targetNode.appendChild(newNode);
sourceRowParent=currSourceRow.parentNode;
sourceRowParent.removeChild(currSourceRow);
}
}


My problem is if i make multiple selections from the source table, only the alternate rows get added to the target table. If I comment out the line 11 (sourceRowParent.removeChild(currSourceRow);), everything works fine, but the requirement is to remove the highlighted rows from the first table and then append it to the second table.
Any ideas why I am not able to access the alternate rows (even the variable 'currSourceRow' holds no value when the previous element is removed).

I am using IE 6.0 as browser.
Any advice would be appreciated.

Thanks
Kiran    <<Less
About | Sitemap | Contact