Web Analytics Made Easy -
StatCounter Changing the style (the color) of another link? - CodingForum

Announcement

Collapse
No announcement yet.

Changing the style (the color) of another link?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Changing the style (the color) of another link?

    How can I change the style (the color) of another link onmouseover?
    something like this:
    <a name="link1" href="page1.htm" onmouseover="changestyle('link2')">link1</a>
    <a name="link2" href="page2.htm">link2</a>
    Hope you can help! Thanks/P

  • #2
    perhaps this may come in handy?
    Code:
    <script type="text/javascript">
         function tog(elemID){
              document.getElementById(elemID).style.display =
              (document.getElementById(elemID).style.display == 'none') ?
              'block' : 'none'
              }
    </script>
    
    <a href="#" onclick="tog('div1')">Style 1</a>
    <a href="#" onclick="tog('div2')">Stlye 2</a>
    <a href="#" onclick="tog('div3')">Style 3</a>
                  <div id="div1" class="class1"><a href="link.htm">THE SAME LINK</a></div>
                  <div id="div2" class="class2"><a href="link.htm">THE SAME LINK</a></div>
                 <div id="div3" class="class3"><a href="link.htm">THE SAME LINK</a></div>
    I know its not EXACTLY what you specified but its all i could think of.
    Last edited by newmand2; Feb 15, 2004, 10:20 AM.
    Dave

    Comment


    • #3
      Something like this?
      Code:
      <html>
      <head>
        <script>
        window.onload = function () {
          document.getElementById('changeomo').onmouseover = function(){
            document.getElementById('changedomo').style.color = '#f00'
          }
        }
        </script>
        ...
      </head>
      <body>
        ...
        <a href="#" id="changeomo">Hello</a>
        <a href="#" id="changedomo">World</a>
        ...
      </body>
      </html>
      David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
      W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

      Comment


      • #4
        Ah, silly me, mis-read the post.

        Comment


        • #5
          Thanks. But is there really no way that I can define which link to change the style of in each case... Something like:

          onmouseover="changestyle('link2','#ffffff')"

          Comment


          • #6
            This is kinda rough draft...
            Code:
            <script type="text/javascript">
            function lite(name, color) {
            	document.getElementById(name).style.color=color;
            }
            </script>
            ...
            <a href="#" onmouseover="lite('link2', '#FFFFFF');" onmouseout="lite('link2', '#000000');">Link</a>
            <a href="#" id="link2">Link 2</a>
            That also requires you to give each link you want to change an ID. So I'm sure there's a better solution out there.

            Comment


            • #7
              Just a quick question... Couldn't you just keep the links the same colour? Why is it that you want to do this? Not being nasty but just wondering.

              In PHP (I don't know whether you use PHP or have access to it etc) you can (i think) do this:

              PHP Code:
              switch($style) {

              case 
              'style1':
              echo (
              '<link href="style1.css" rel="stylesheet" type="text/css">');
              break;

              case 
              'style2':
              echo (
              '<link href="style2.css" rel="stylesheet" type="text/css">');
              break;

              case 
              'style3':
              echo (
              '<link href="style3.css" rel="stylesheet" type="text/css">');
              break;

              default:
              echo (
              '<link href="style.css" rel="stylesheet" type="text/css">');

              And then the links could be www.yourdomain.com/index.php?style=style1


              Just a thought
              Dave

              Comment

              Working...
              X