Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Retriving an alt value

    <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

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <!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)
    Last edited by mark87; 06-11-2005 at 04:06 PM.

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is very important that this works in FF

    thanks for your help though

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    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.
    Code:
    <p id="moreInfo">more info</p>
    
    <p title="test" onmouseover="moreInfo(this.title)">test</p>

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Bill Posters
    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.
    Code:
    <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



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •