SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: how do I?

  1. #1
    SitePoint Member
    Join Date
    Sep 2003
    Location
    GERMANY
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question how do I?

    plz!
    how do i get this thing i copied someplace to work?
    My intention is to give a text some letters, that "open up" to a linked word by a rollover function. i got it running with this script, except that after the linked letter the text continues in a new line.
    can u tell me how to get the "blabla and so on" in the same line as the "B"??
    thanx in advance...here´s the script:
    in the head goes:
    ____________________________________
    <script language="JavaScript"><!--
    function changeContent(what,text) {
    if (document.all)
    what.innerHTML = text;
    else if (document.layers) {
    what.document.open();
    what.document.write(text);
    what.document.close();
    }
    }
    _____________________________________
    and in the body i put:
    _________________________
    <a href="anyplace.html">
    <div onMouseOver="changeContent(this,'Before')"
    onMouseOut="changeContent(this,'B')">
    <nobr>B</nobr>
    </div>
    </a>
    <a>
    labla and so on
    __________________________
    (having defined a before as some style sheet)

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    document.all is IE only, everyone else uses document.getElementById.
    So...you only had to change the order (tested in IE6, NN6.1)

    <script>
    <!--
    function changeContent(what,text) {
    if (document.layers) {
    what.document.open();
    what.document.write(text);
    what.document.close();
    }
    else
    what.innerHTML = text;
    }
    //-->
    </script>

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi sebizwo. Basically I made 2 changes.
    1) I changed DIV to SPAN because a div is a block element. This was causing the line-break.
    2) Instead of "if (document.all)" I used "if (typeof(what.innerHTML) == 'string')". This tests for the existence of the property before we use it.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title></title>
    <style type='text/css'>
    html {margin:0; padding:0;}
    body {
      color:#000; background:#fff;
      margin:0; padding:30px;
      font-family:verdana,arial,sans-serif; font-size:16px;
    }
    a {color:#008; background:transparent; text-decoration:underline;}
    a:hover {color:#008; background:#ccc; text-decoration:none;}
    </style>
    <script type='text/javascript'>
    function changeContent(what, text) {
      if (typeof(what.innerHTML) == 'string') {
        what.innerHTML = text;
      }  
      else if (document.layers) {
        what.document.open();
        what.document.write(text);
        what.document.close();
      }
    }
    </script>
    </head>
    <body>
    
    <a href="anyplace.html"><span onmouseover="changeContent(this,'Before')"
      onmouseout="changeContent(this,'B')">B</span></a>laBlaBla
    
    </body>
    </html>

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops! Vinny, you beat me to it!

  5. #5
    SitePoint Member
    Join Date
    Sep 2003
    Location
    GERMANY
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx a lot you Guys...luv u a lot!
    perfect!

  6. #6
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi sebizwo,
    I forgot to mention -- that code assumes the surfing browsers knows one or the other method -- somewhere on the page you need to check if javascript is enabled and/or if the browser version is 4+

    Hi Mike,
    sometimes, but not often, I get lucky and get to a post first

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

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