Lille demo herunder.
Funktionerne bag ret og slet knap er bare for illustrationens skyld; dem har du sikkert din egen kode til.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd"><html>
<head>
<title>TextDiv display </title>
<style>
body {
font:100% sans-serif;
}
.editLink {
cursor: pointer;
}
.t1 {
border-collapse: collapse;
}
td {
padding: 2px 4px 2px 4px ;
}
#PopMenuID{
position: absolute;
height:100px; width:100px;
border: 2px outset grey;
padding: 2px 2px 2px 5px;
background-color: lightyellow;
display: none;
z-index: 100;
}
</style>
<script type="text/javascript">
//Global vars:
var oPopMenu;
var oRows;
var row;
function popMenu(span) {
resetRowColor();
row = span.parentNode.parentNode;
row.style.backgroundColor = "lightyellow";
oPopMenu.style.left = (span.parentNode.offsetLeft + 30) + "px";
oPopMenu.style.top = (span.parentNode.offsetTop +10) + "px";
oPopMenu.style.display = 'block';
}
function resetRowColor() {
for (var i = 0; i < oRows.length; i++) {
oRows[i].style.backgroundColor = "white";
}
}
function popMenuClose() {
oPopMenu.style.display = 'none';
}
function doDelete() {
row.parentNode.removeChild(row);
popMenuClose();
}
function doEdit() {
var oTDs = row.getElementsByTagName("TD");
for (var i = 0; i < oTDs.length-1; i++) {
var value = oTDs[i].firstChild.nodeValue;
var oInp = document.createElement("input");
oInp.value = value ;
oInp.size = value.length;
oTDs[i].removeChild(oTDs[i].firstChild);
oTDs[i].appendChild(oInp);
}
popMenuClose();
}
window.onload = function() {
oPopMenu = document.getElementById("PopMenuID");
oPopMenu.style.display = 'none'
oRows = document.getElementById("demoTable").getElementsByTagName("TR");
}
</script>
</head>
<body>
<table id="demoTable" class="t1" border="1">
<tr>
<th>Aaa</th>
<th>Bbb</th>
<th>Ccc</th>
<th>Edit</th>
</tr>
<tr>
<td>1:1</td>
<td>1:2</td>
<td>1:3</td>
<td> <span class="editLink" onmouseover="popMenu(this)" >E</span></td>
</tr>
<tr>
<td>2:1</td>
<td>2:2</td>
<td>2:3</td>
<td> <span class="editLink" onmouseover="popMenu(this)" >E</span></td>
</tr>
<tr>
<td>3:1</td>
<td>3:2</td>
<td>3:3</td>
<td> <span class="editLink" onmouseover="popMenu(this)" >E</span></td>
</tr>
</table>
<div id="PopMenuID" >
<input type="button" value="X" onclick="popMenuClose(); resetRowColor(); return false;" style="float:right;"><br><br>
<input type="button" value=" Edit " onclick="doEdit(); return false;" ><br>
<input type="button" value=" Delete " onclick="doDelete(); return false;" >
</div>
</body>
</html>