M
Matt White
Hello,
I am creating a list of products, some of which have long names that
should be truncated at a certain point. I would like to display the
full name of the product when the user does a mouseover in a <div>,
and set that <div>'s position to be just to the right of the mouse
pointer. I have written code that does this successfully in IE, but in
FireFox it always wants to display in the top left corner. It seems
that the element.style.top and .left attributes refuse to be set in
FireFox. Does anyone know what I need to change to get it to work in
both browsers? Thanks.
### Javascript Code ###
<script type="text/javascript">
function showName(event, text) {
var fullName = document.getElementById('full_product_name');
if(document.all) {
fullName.innerText = text;
} else {
fullName.textContent = text;
}
fullName.style.position = 'absolute';
fullName.style.display = 'block';
fullName.style.top = event.clientY;
fullName.style.left = event.clientX + 2;
}
function hideName() {
document.getElementById('full_product_name').style.display = 'none';
}
</script>
### Applicable HTML ###
....
<td><span onMouseOver='javascript:showName(event, "FULL PRODUCT NAME
GOES HERE");' onMouseOut="javascript:hideName();">TRUNCATED NAME GOES
HERE</span></td>
....
### Applicable Stylesheet ###
#full_product_name {
display: none;
background-color:#ffffdd;
border: 1px solid black;
font-size: 15px;
font-family: Arial, Helvetica, sans-serif;
}
I am creating a list of products, some of which have long names that
should be truncated at a certain point. I would like to display the
full name of the product when the user does a mouseover in a <div>,
and set that <div>'s position to be just to the right of the mouse
pointer. I have written code that does this successfully in IE, but in
FireFox it always wants to display in the top left corner. It seems
that the element.style.top and .left attributes refuse to be set in
FireFox. Does anyone know what I need to change to get it to work in
both browsers? Thanks.
### Javascript Code ###
<script type="text/javascript">
function showName(event, text) {
var fullName = document.getElementById('full_product_name');
if(document.all) {
fullName.innerText = text;
} else {
fullName.textContent = text;
}
fullName.style.position = 'absolute';
fullName.style.display = 'block';
fullName.style.top = event.clientY;
fullName.style.left = event.clientX + 2;
}
function hideName() {
document.getElementById('full_product_name').style.display = 'none';
}
</script>
### Applicable HTML ###
....
<td><span onMouseOver='javascript:showName(event, "FULL PRODUCT NAME
GOES HERE");' onMouseOut="javascript:hideName();">TRUNCATED NAME GOES
HERE</span></td>
....
### Applicable Stylesheet ###
#full_product_name {
display: none;
background-color:#ffffdd;
border: 1px solid black;
font-size: 15px;
font-family: Arial, Helvetica, sans-serif;
}