DHTML
  Home arrow DHTML arrow Page 2 - Rough Guide To The DOM (part 2)
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DHTML

Rough Guide To The DOM (part 2)
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2001-05-09

    Table of Contents:
  • Rough Guide To The DOM (part 2)
  • Making The Swap()
  • Turning The Tables
  • Well-Formed
  • In The Frame
  • Branching Out
  • Dumbing It Down
  • Conclusions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Rough Guide To The DOM (part 2) - Making The Swap()


    (Page 2 of 8 )

    The first item on the agenda today is an illustration of how you can use the DOM to accomplish one of the most popular dHTML applications - the image swap. Take a gander at the following HTML document:

    <html> <head> </head> <body> <a href="http://www.melonfire.com/" onMouseOver="javascript:imageSwap();" onMouseOut="javascript:imageSwap();"><img id="logo" src="logo_n.gif" width=50 height=50 border=0></a> </body> </html>

    Now, I've set this up so that "mouseover" and "mouseout" events on the image are handled by the JavaScript function imageSwap(). This function is responsible for swapping the image each time an event occurs - so let's take a look at it.

    <script language="JavaScript"> var normal = "logo_n.gif"; var hover = "logo_h.gif"; function imageSwap() { var imageObj = document.getElementById("logo"); var imageSrc = imageObj.getAttribute("src"); if (imageSrc == normal) { imageObj.setAttribute("src", hover); } else { imageObj.setAttribute("src", normal); } } </script>

    If you remember what I taught you last time, none of this should come as a surprise. I've first defined the "normal" and "hover" state images, and then created a function called imageSwap(), which is called whenever the mouse moves over and out of the image.

    The imageSwap() function obtains a reference to the image via its ID, and then obtains the current value of the image's "src" attribute. It then checks the value against the values of the "normal" and "hover" variables, and changes the image source appropriately.

    This article copyright Melonfire 2001. All rights reserved.

    More DHTML Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    DHTML ARTICLES

    - Rough Guide To The DOM (part 2)
    - Rough Guide To The DOM (part 1)
    - Filters And Transitions In IE5
    - Understanding Embedded Fonts





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway