onmouseover and out validation

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Apr 2008
Posts: 496
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

onmouseover and out validation

 
0
  #1
Apr 4th, 2009
Hi,

I use onmouseover and out for <td> or <div> to change either backgroung image or color. However, onmouseover and out are not validated for HTML. w3scholls HTML validator doesn't validate them. How can i solve this problem?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: onmouseover and out validation

 
0
  #2
Apr 4th, 2009
Use the eventListener, instead of assigning it directly on those tags that you have mentioned. The only elements that will validates with those events, are the —
<!-- <a> <img .../> <form><elements></form> <area> --> .
And be sure to use only elements that is valid in the DOCTYPE that you are using.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: onmouseover and out validation

 
0
  #3
Apr 4th, 2009
why use javascript for this ? CSS is perfectly capable of doing this without the scripting overhead.

  1. /* Example changing a td elements background colour */
  2. td {
  3. background-color:transparent;
  4. }
  5. td:hover {
  6. background-color:yellow;
  7. }
  8.  
  9. /* Example changing a div's background image */
  10. div {
  11. background:transparent url('some_image.jpg');
  12. }
  13. div:hover {
  14. background:transparent url('another_image.jpg');
  15. }
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 496
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

Re: onmouseover and out validation

 
0
  #4
Apr 5th, 2009
Hi Fungus,

I want something workes in all browsers. Your doesn't work in IE.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: onmouseover and out validation

 
0
  #5
Apr 6th, 2009
Here a simple demo to get you started.
You can validate this entry with W3Cs markup validatation tool's via direct input. Just copy paste the whole code:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6. <meta http-equiv="X-UA-Compatible" content="IE=5; IE=EmulateIE7" />
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <meta http-equiv="Content-Style-Type" content="text/css" />
  9. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  10. <title>JavaScript DEMO</title>
  11. <style type="text/css" charset="utf-8" media="screen,handheld">
  12. /* <![CDATA[ */
  13. body, div, table, td, th {
  14. font: normal normal normal 90%/1.4 "Trebuchet MS", Tahoma, Verdana, Helvetica, Arial, Sans-Serif; color: #000; text-align: center }
  15. div {
  16. height auto;
  17. margin: 5em auto 5em auto;
  18. min-height: 200px;
  19. text-align: left;
  20. width: 95%; }
  21.  
  22. div.red {
  23. background-color: #E00; }
  24.  
  25. div.white {
  26. background-color: #fff; }
  27.  
  28. /* ]]> */
  29. </style>
  30. <script type="text/javascript">
  31. /* <![CDATA[ */
  32. var div;
  33. var my = function() {
  34.  
  35. function red() {
  36. if ( document.all ) {
  37. document.all.myDiv.className = "red"; }
  38. else if ( document.getElementById ) {
  39. document.getElementById("myDiv").className = "red"; }
  40. }
  41.  
  42. function white() {
  43. if ( document.all ) {
  44. document.all.myDiv.className = "white"; }
  45. else if ( document.getElementById ) {
  46. document.getElementById("myDiv").className = "white"; }
  47. }
  48.  
  49. function addEvents() {
  50. div = ( document.all ) ? document.all.myDiv : document.getElementById("myDiv");
  51.  
  52. if ( document.attachEvent ) {
  53. div.attachEvent("onmouseover",red);
  54. div.attachEvent("onmouseout",white); }
  55. else if ( document.addEventListener ) { div.addEventListener("mouseover",red,false);
  56.  
  57. div.addEventListener("mouseout",white,false); }
  58. }
  59.  
  60. return {
  61. colors : addEvents }
  62. }();
  63.  
  64. if ( window.attachEvent )
  65. window.attachEvent("onload",my.colors);
  66. else if ( window.addEventListener )
  67. window.addEventListener("load",my.colors,false);
  68. else
  69. window.onload = my.colors;
  70. /* ]]> */
  71. </script>
  72.  
  73. </head>
  74. <body>
  75. <div class="white" id="myDiv">Try MouseOver and MousedOut here!</div>
  76. <div id="div1"><a href="#">Div Filler</a></div>
  77. </body>
  78. </html>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: onmouseover and out validation

 
0
  #6
Apr 6th, 2009
Oops! I forgot to remove the charset attribute in the <style> tag.
Kindly remove it to make the markup valid. Good day...
Last edited by essential; Apr 6th, 2009 at 1:51 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC