943,718 Members | Top Members by Rank

Ad:
Apr 4th, 2009
0

onmouseover and out validation

Expand Post »
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
Similar Threads
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
Apr 4th, 2009
0

Re: onmouseover and out validation

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.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Apr 4th, 2009
0

Re: onmouseover and out validation

why use javascript for this ? CSS is perfectly capable of doing this without the scripting overhead.

css Syntax (Toggle Plain Text)
  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. }
Reputation Points: 66
Solved Threads: 56
Posting Pro in Training
Fungus1487 is offline Offline
459 posts
since Apr 2007
Apr 5th, 2009
0

Re: onmouseover and out validation

Hi Fungus,

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

Thanks
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
Apr 6th, 2009
0

Re: onmouseover and out validation

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:

javascript Syntax (Toggle Plain Text)
  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>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Apr 6th, 2009
0

Re: onmouseover and out validation

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.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Dynamic DIV tags don't work.
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Websites Takeover - Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC