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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get text of a link

    Hi,

    I would need to obtain via a javascript function the text enclosed by the link. Example:

    <a href="javascript:myFunction(this)">this is the text!</a>

    Somehow the function "myFunction(..)" should have access to the text "this is the text". Of course, I could pass it directly to the function as a parameter, but I would be greate if that wouldn't be necessary!

    Thanks for any ideas!

    Axel

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <a href="http://yourdomain.com/yourpage.html" onclick="return yourFunction(this)">Anchor Text</a>
    ...
    function yourFunction(anchor)
      { anchorText = anchor.firstChild.nodeValue;
         /* more stuff */
         return false;
      }
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

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