phaedrus28
Programmer
Hi,
I'm trying to code a sortable list using links on each list item, and I'm using the DOM to shift the items around. The code below illustrates the problem I'm experiencing - in IE 6/7 insertBefore works fine, but in Firefox insertBefore doesn't work unless you click a given link several times.
I would have expected Firefox to update the display straight away - appendChild works fine, but I need insertBefore to work.
Does anyone know if there is a workaround for this?
<html>
<head>
<script language="javascript">
function test(li) {
var e = document.getElementById('li' + li);
var ol = document.getElementById('list');
var s = e.previousSibling;
ol.removeChild(e);
ol.insertBefore(e, s);
}
</script>
</head>
<body>
<ol id="list">
<li id="li1">One <a href="#" onclick="test(1);">1</a></li>
<li id="li2">Two <a href="#" onclick="test(2);">2</a></li>
<li id="li3">Three <a href="#" onclick="test(3);">3</a></li>
<li id="li4">Four <a href="#" onclick="test(4);">4</a></li>
</ol>
</body>
</html>
I'm trying to code a sortable list using links on each list item, and I'm using the DOM to shift the items around. The code below illustrates the problem I'm experiencing - in IE 6/7 insertBefore works fine, but in Firefox insertBefore doesn't work unless you click a given link several times.
I would have expected Firefox to update the display straight away - appendChild works fine, but I need insertBefore to work.
Does anyone know if there is a workaround for this?
<html>
<head>
<script language="javascript">
function test(li) {
var e = document.getElementById('li' + li);
var ol = document.getElementById('list');
var s = e.previousSibling;
ol.removeChild(e);
ol.insertBefore(e, s);
}
</script>
</head>
<body>
<ol id="list">
<li id="li1">One <a href="#" onclick="test(1);">1</a></li>
<li id="li2">Two <a href="#" onclick="test(2);">2</a></li>
<li id="li3">Three <a href="#" onclick="test(3);">3</a></li>
<li id="li4">Four <a href="#" onclick="test(4);">4</a></li>
</ol>
</body>
</html>