SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Onmouseover navigation image change.

    Hi as title states, i'm trying to make a navigation where the images change on mouseover.
    PHP Code:
    <script>
    function 
    findNav() {
        var 
    nav document.getElementById('nav-topbar').getElementsByTagName('img');
        for( 
    i in nav ) {
            if (
    nav[i].id != 'nav-on' && nav[i].id) {
                
                
    nav[i].onmouseover = function() { mouseHover(this.id1); };
                
    nav[i].onfocus = function() { mouseHover(this.id1); };
                
                
    nav[i].onmouseout = function() { mouseHover(this.id0); };
                
    nav[i].onblur = function() { mouseHover(this.id0); };
            }
        }
    }

    function 
    mouseHover(idstate) {
        if (
    state) {
            
    document.getElementById(id).src 'images/nav/' id '-on.gif';
        } else {
            
    document.getElementById(id).src 'images/nav/' id '.gif';
        }
    }

    window.onload = function() {
        
    findNav();
    }
    </script> 
    It's in an external js, not inline but anyway..
    I get a few javascript warnings on the firefox error console, which is what i'm trying to fix.

    Although this script works, some of the images don't have an id, because the navigation has vertical-line images that serve to split up the navigation items aesthetically.

    And thus the line: if (nav[i].id != 'nav-on' && nav[i].id)
    seems to throw a warning, which is no big deal but i would like to know if theres an alternate way to check if an image has an id or not, some sort of a function like PHP has with isset()?

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, figured it out.

    Changing

    if (nav[i].id != 'nav-on' && nav[i].id)

    to

    if (nav[i].id && nav[i].id != 'nav-on')

    fixed it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •