Results 1 to 3 of 3

Thread: function using "a" or "href"

  1. #1
    Join Date
    Sep 2008
    Location
    Midland, Texas
    Posts
    52
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Question function using "a" or "href"

    I wonder if anyone can help me with this. I am trying to write up a function that cycles through the <a href=”…. >whatever link</a> when the user clicks the pseudo link <a href=”javascript:functionname()”>. I know that pretty much all HTML elements on a page can be referred to in array format (forms[], images[], etc.), but I am not sure how or if it is even possible to do that with <a href…>. Any help will be greatly appreciated. Thanks in advance.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    If you would like this for only one page, put the following inside the <head> tag.

    Code:
    <script type="text/javascript">
    function functionname() {
         if(document.getElementById) {
              var anchorTags = document.getElementByTagName("a");
              for(var lcount=0; lcount<anchorTags.length; lcount++)
              {
                  /* do something with each individual anchor tag */
                  /* anchorTags[lcount] represents the current anchor tag within the loop */
              }
         }
    }
    </script>
    if you would like this for more then one page, create an external javascript (js) file and link to the script on each page using the following code

    Code:
    <script type="text/javascript" href="path/to/script">
    </script>

    to access the script itself use the following code located where ever you wished to use the script

    Code:
    <a href="javascript:functionname()">Get all links on this page</a>

  3. #3
    Join Date
    Sep 2008
    Location
    Midland, Texas
    Posts
    52
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    Thanks. I appreciate you help.

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
  •