How to change cell color dinamically ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pplers
    New Member
    • Apr 2007
    • 60

    How to change cell color dinamically ?

    I'd like to know if there's a way to make the color of a cell/button change using onMouseOver. Is there some sort of "built-in" function to do this ?



    Thank you....

    p.s: If possible, the color should be random.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, pplers.

    You must have meant to post this in the JavaScript forum. All taken care of, now.

    Comment

    • xNephilimx
      Recognized Expert New Member
      • Jun 2007
      • 213

      #3
      Hi there.
      There's no built in function to do that, as there's not only one way, but a series of methods for manipulating the styles of an element. Try something like this, this is the way that I like the most cause it's non intrusive script:

      [CODE=javascript]
      window.onmouseo ver = Over;

      function Over(e) {
      var obj = e.target || window.event.sr cElement;
      if(obj.tagName == "TD") {
      obj.style.backg round = "#ffc";
      obj.onmouseout = Out;
      }
      }

      function Out(e) {
      var obj = e.target || window.event.sr cElement;
      if(obj.tagName == "TD") {
      obj.style.backg round = "none";
      }
      }
      [/CODE]

      This will make any td of any table "highlighta ble" when you hover the mouse on it.
      If you want to make it only work on tables with a certain class name you'll then want to check the obj's class name, like this:


      [CODE=javascript]
      window.onmouseo ver = Over;

      function Over(e) {
      var obj = e.target || window.event.sr cElement;
      if(obj.tagName == "TD") {
      if(obj.classNam e == "theClass") {
      obj.style.backg round = "#ffc";
      obj.onmouseout = Out;
      }
      }
      }

      function Out(e) {
      var obj = e.target || window.event.sr cElement;
      if(obj.tagName == "TD") {
      if(obj.classNam e == "theClass") {
      obj.style.backg round = "none";
      }
      }
      }
      [/CODE]

      Kind regards,
      The_Nephilim

      Originally posted by pplers
      I'd like to know if there's a way to make the color of a cell/button change using onMouseOver. Is there some sort of "built-in" function to do this ?



      Thank you....

      p.s: If possible, the color should be random.

      Comment

      Working...