SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot Ace02's Avatar
    Join Date
    Jun 2004
    Location
    SitePoint.com
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Need some help...

    I've just about given up with this... I've been trying simply to add some text underneath a link when you click on it, and not have it be part of the link, but just some normal text. Any help that anyone can give will be greatly appreciated.
    ~("~) - Aloha!

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in its simplest form

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    </
    head>

    <
    body>
    <
    a href="#" onclick="document.getElementById('LkTxt').innerHTML='My Text';" >Link</a><br>
    <
    span id=LkTxt ></span>
    </
    body>

    </
    html
    a bit more complex

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    <
    script language="JavaScript" type="text/javascript">
    <!--
    function 
    AddText(obj,txt){
     
    txt=document.createTextNode(txt);
     
    obj.parentNode.insertBefore(txt,obj)
     clone=
    obj.cloneNode(true);
     
    obj.parentNode.removeChild(obj);
     
    txt.parentNode.insertBefore(clone,txt)
     
    txt.parentNode.insertBefore(document.createElement('BR'),txt)

    }

    //-->
    </script></head>

    <body>
    <center><a href="#" onclick="AddText(this,'My Text');" >Link</a><br>
    </center></body>

    </html> 
    or

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    <
    script language="JavaScript" type="text/javascript">
    <!--
    function 
    AddText(obj,txt){
     
    txtobj=document.createTextNode(txt);
     
    div=document.createElement('DIV');
     
    div.style.position='absolute';
     
    div.style.width='100px';
     
    div.style.height='20px';
     
    div.style.backgroundColor='yellow';
     
    div.style.border='solid black 1px';
     
    div.style.textAlign='center';
     
    div.appendChild(txtobj);
     
    document.getElementsByTagName('BODY')[0].appendChild(div);
     
    div.style.top=(zxcPos(obj)[1]+20)+'px';
     
    div.style.left=(zxcPos(obj)[0]-div.offsetWidth/2+obj.offsetWidth/2)+'px';
    }

    function 
    zxcPos(zxc){
     
    zxcObjLeft zxc.offsetLeft;
     
    zxcObjTop zxc.offsetTop;
     while(
    zxc.offsetParent!=null){
      
    zxcObjParent=zxc.offsetParent;
      
    zxcObjLeft+=zxcObjParent.offsetLeft;
      
    zxcObjTop+=zxcObjParent.offsetTop;
      
    zxc=zxcObjParent;
     }
     return [
    zxcObjLeft,zxcObjTop];
    }



    //-->
    </script></head>

    <body>
    <center>
    <a href="#" onclick="AddText(this,'Text 1');" >Link</a><br>
    <br>
    <a href="#" onclick="AddText(this,'Text 2');" >Link</a><br>
    </center></body>

    </html> 
    Last edited by vwphillips; Jun 2, 2005 at 11:46.

  3. #3
    SitePoint Zealot Ace02's Avatar
    Join Date
    Jun 2004
    Location
    SitePoint.com
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you!
    ~("~) - Aloha!

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    posts crossed see update


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
  •