[thelist] Friday Freebie
Jeff Howden
jeff at alphashop.net
Fri Jun 8 16:32:51 CDT 2001
<tip type="JavaScript">
Building a DHTML app that has to support ie5+ on windows & mac? be careful
of the use of swapNode(). according to ms documentation, this method is
supported in ie5 on the mac, but in reality it is not. i found this out the
hard way.
there are definite speed benefits to using the swapNode() method so it makes
sense to use it whenever possible. however, make sure to do a method
support check first and, if critical to the functionality of the app,
perform the swap using the brute force method.
the html:
<table id="listTable"
cellpadding="2"
cellspacing="1"
border="0">
<tr>
<td><strong>one</strong></td>
<td>1</td>
</tr>
<tr>
<td><strong>two</strong></td>
<td>2</td>
</tr>
<tr>
<td><strong>three</strong></td>
<td>3</td>
</tr>
<tr>
<td><strong>four</strong></td>
<td>4</td>
</tr>
<tr>
<td><strong>five</strong></td>
<td>5</td>
</tr>
</table>
swapping the contents of the first cell between the first and second row...
set up some variables for quick reference:
var cellObj0 = listTable.rows[0].cells[0];
var cellObj1 = listTable.rows[1].cells[0];
the swapNode() method:
cellObj0.swapNode(cellObj1);
the brute force method:
var swapHTML = cellObj0.innerHTML;
cellObj0.innerHTML = cellObj1.innerHTML;
cellObj1.innerHTML = swapHTML;
combining the two and using method support checking:
if(cellObj0.swapNode)
{
cellObj0.swapNode(cellObj1);
}
else
{
var swapHTML = cellObj0.innerHTML;
cellObj0.innerHTML = cellObj1.innerHTML;
cellObj1.innerHTML = swapHTML;
}
</tip>
good luck,
Jeff Howden
Sr. Web Application Engineer
jeff at alphashop.net
AlphaShop Network Services
http://www.alphashop.net/
Mobile: 503.804.9938
Voice: 541.681.4078
Fax: 541.681.4084
AIM - Active Information Management
More information about the thelist
mailing list