Loading ...
Sorry, an error occurred while loading the content.
 

change hyperlink using javascript

Expand Messages
  • joeandtelus
    I have a hyperlink named hoursLink2 Link in javascript I want to change the visibility of the hyperlink to visible
    Message 1 of 2 , Dec 1, 2003
      I have a hyperlink named "hoursLink2"
      <a href="page.htm" name="hoursLink2">Link</a>
      in javascript I want to change the visibility of the hyperlink to
      visible and hidden depending on other values.
      I have tried:
      document.hoursLink2.visibility='hidden';
      and
      document.myForm.hoursLink2.visibility='hidden';
      neither of these work. How can I manipulate a link using javascript?
    • Jon Stephens
      1. Give the link an id attribute rather a name attribute: Link 2. Use document.getElementById to obtain a DOM reference
      Message 2 of 2 , Dec 2, 2003
        1. Give the link an id attribute rather a name attribute:

        <a href="page.htm" id="hoursLink2">Link</a>

        2. Use document.getElementById to obtain a DOM reference to that link:

        var myLink = document.getElementById("hoursLink2");

        3. Set that object's style property. You have two choices here:

        myLink.style.visibility = "hidden";
        // makes the link invisible but doesn't remove it from the page layout

        myLink.style.display = "none";
        // completely removes the link from the page layout

        > Date: Mon, 01 Dec 2003 17:21:15 -0000
        > From: "joeandtelus" <joeandtelus@...>
        > Subject: change hyperlink using javascript
        >
        > I have a hyperlink named "hoursLink2"
        > <a href="page.htm" name="hoursLink2">Link</a>
        > in javascript I want to change the visibility of the hyperlink to
        > visible and hidden depending on other values.
        > I have tried:
        > document.hoursLink2.visibility='hidden';
        > and
        > document.myForm.hoursLink2.visibility='hidden';
        > neither of these work. How can I manipulate a link using javascript?
      Your message has been successfully submitted and would be delivered to recipients shortly.