I have a div that I want to appear directly below a table cell when the table cell is clicked. Here is a sample of my code so far…
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">
function toggleDownloadSelectionDialog(divToggle,divId,event){
pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById(divToggle).offsetLeft;
pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById(divToggle).offsetTop;
alert(pos_y+" "+pos_x+" "+divId);
document.getElementById(divId).style.top = pos_y;
document.getElementById(divId).style.left = pos_x;
document.getElementById(divId).style.display = 'block';
}
</script>
</head>
<body>
<div class="div_downloadDialog" id="div_hidden1" style="display: none; top: 0; left: 0; position: absolute;">This div is hidden</div>
<table class="Oligo_Diversity">
<tr>
<td>blah</td><td>blah</td><td>blah</td>
</tr>
<tr>
<td><div id="div_toggle1" onclick="toggleDownloadSelectionDialog('div_toggle1','div_hidden1',event);">click here for download dialog</div></td>
<td>blah</td>
<td>blah</td>
</tr>
</table>
</body>
</html>
I would like the hidden download div to appear directly below the table cell it is clicked on. My javascript seems to get the position but I’m having trouble passing this information to the div. Removing the DOCTYPE will make this work but for the project I’m working on I need a doctype. Any suggestions?
Set
position: absolutefor theDIVas sv_in said.This line also may cause troubles in IE:
If you’ll run this in IE, ternary operator finds the condition true and returns
trueafter?.Switch the line to:
And the same on next line for
pos_y.When using
<!DOCTYPE html>also units have to be used in style definitions: