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

    Exclamation <a href="XYZ"></a> append script help

    Hi,
    I have a script that is designed to append all the links on a page with the exstension '&layout=jp ' for the href.

    onload = function () { for (var i = 0; i < document.links.length; i++) document.links[i].href = document.links[i].href + '&layout=jp'}

    I would like to be able exclude certain links from this happening too, ideally through their css class/id ... but I am not sure where to start?

    Any help would be much appreciated.

    Best,
    P

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Welcome to the forums. Please be mindful to use the CODE tags and indent for readability when posting code.

    What you can do is run through each link in the for loop and test for a class as you go, e.g.
    Code:
      window.onload = function () {
        var links= document.getElementsByTagName('a');
        for (var i = 0, l= links.length; i<l; i++) {
            if ( links[i].className == 'changelink' ) {
                links[i].href += '&layout=jp';
            }
        }
      };
    I've altered it slightly, using a DOM method to get all the anchor tag elements, then checking each one for a specific className. The loop is slightly different as well, assigning the links length value once rather than evaluating it on each iteration.

  • Users who have thanked bdl for this post:

    phellyer (02-01-2010)

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you for your help BDL, much appreciated.

    Best


  •  

    Tags for this Thread

    Posting Permissions

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