User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 374,181 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,414 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1920 | Replies: 11 | Solved
Reply
Join Date: Jul 2006
Location: Deptford, London
Posts: 916
Reputation: MattEvans will become famous soon enough MattEvans will become famous soon enough 
Rep Power: 5
Solved Threads: 46
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: document.getElementById problem

  #11  
Feb 27th, 2008
Alternatively, try this trick, if you don't mind presetting the available colors ( in a way, it's better because those colours can be defined in the CSS ). This works by dynamically changing the class of the containing element, the CSS 'cascade' effect sorts out the rest:

<html>
  <head>
    <title>Color changing magic with a classname trick</title>
    <style type="text/css">
      div.red_links a
      {
        color:red;
      }
      div.blue_links a
      {
        color:blue;
      }
    </style>
    <script type="text/javascript">
      function set_linkcolor( to )
      {
        document.getElementById( "color_state" ).className = 
              to + "_links";
      }
    </script>
  </head>
  <body>
    <div id="color_state" class="red_links">
      <ul>
        <li><a>An anchor</a></li>
        <li><a>Another</a></li>
        <li><a>And another</a></li>
        <li>Some normal text</li>
        <li>Some more..</li>
        <li>And some more</li>
      </ul>
    </div>
    <span onmousedown="set_linkcolor( 'blue' )" 
         onmouseup="set_linkcolor( 'red' )" 
         style="border:solid 1px black;">
      Click me!
    </span>
  </body>
</html>
Last edited by MattEvans : Feb 27th, 2008 at 2:59 am.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Jan 2008
Posts: 18
Reputation: Begjinner is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Begjinner's Avatar
Begjinner Begjinner is offline Offline
Newbie Poster

Re: document.getElementById problem

  #12  
Feb 27th, 2008
Thanks MattEvans, after a short trying period I got it working with your 'system'.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC