...

View Full Version : Retriving an alt value



JAVAEOC
06-11-2005, 03:46 PM
<div alt="test" onmouseover="moreInfo(this.alt)">test</div>

the JS function:

function moreInfo(info){
document.getElementById("moreInfo").innerHTML = info;
}

prity simple, when I move over the div, the moreInfo section should display the alt text, but it doesnt it displayes undefined.... :(

thanks for any help

mark87
06-11-2005, 04:04 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;

charset=iso-8859-1">

<title>Untitled Document</title>

<style type="text/css">
</style>

<script>
function moreInfo(info){
document.getElementById("moreInfo").innerHTML = info;
}
</script>

</head>

<body>
<div id="moreInfo" title="This is the ALT text."

onmouseover="moreInfo(this.title)">This is the normal text.</div>
</body>

</html>

Works for me...

Ah, it worked in IE, not FF... change the '.alt''s to 'title'. :) (edited above)

JAVAEOC
06-11-2005, 04:32 PM
it is very important that this works in FF :(

thanks for your help though

Bill Posters
06-11-2005, 04:53 PM
As mark87 has pointed out above, using alt attribute on non-img elements is pointless, when you could just as easily use the more appropriate title attribute.
His example works fine once you've changed the alt attribute on the div (or p) element to a title attribute and pass the element title to the function instead of the alt attribute - as he has also already said and shown.

e.g.

<p id="moreInfo">more info</p>

<p title="test" onmouseover="moreInfo(this.title)">test</p>

JAVAEOC
06-11-2005, 04:57 PM
As mark87 has pointed out above, using alt attribute on non-img elements is pointless, when you could just as easily use the more appropriate title attribute.
His example works fine once you've changed the alt attribute on the div (or p) element to a title attribute and pass the element title to the function instead of the alt attribute - as he has also already said and shown.

e.g.

<p id="moreInfo">more info</p>

<p title="test" onmouseover="moreInfo(this.title)">test</p>


I tryed this with onmouseover="moreInfo(this.titel)"


hahah omg, I mispelled it... thanks guys

:eek: :eek: :eek: :eek:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum