SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function that swaps out images not working

    Here is the function I'm trying to use:

    Code:
    function expand_collapse(content_div, expand_image)
    {
    	var select_div = document.getElementById(content_div);
    	var select_image = document.getElementById(expand_image);
    	
    	if(select_div.style.display == 'none')
    		select_div.style.display = 'block';
    	else
    		select_div.style.display = 'none';
    		
    	if(select_image.src == 'images/COLLAPSE.gif')
    		select_image.src = 'images/EXPAND.gif';
    	else
    		select_image.src = 'images/COLLAPSE.gif';
    		
    }
    I essentially pass it two variables, both of which are ID tags for the appropriate div and image. the div displays or hides correctly, but the image is not changing. Does anyone see anything wrong with my function?

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this.
    Code:
    alert(select_image.src)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    NY, USA
    Posts
    712
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jhorra View Post
    Here is the function I'm trying to use:

    Code:
    function expand_collapse(content_div, expand_image)
    {
    	var select_div = document.getElementById(content_div);
    	var select_image = document.getElementById(expand_image);
    	
    	if(select_div.style.display == 'none')
    		select_div.style.display = 'block';
    	else
    		select_div.style.display = 'none';
    		
    	if(select_image.src == 'images/COLLAPSE.gif')
    		select_image.src = 'images/EXPAND.gif';
    	else
    		select_image.src = 'images/COLLAPSE.gif';
    		
    }
    I essentially pass it two variables, both of which are ID tags for the appropriate div and image. the div displays or hides correctly, but the image is not changing. Does anyone see anything wrong with my function?
    alert(select_image.src)

    ...and see what that is.

    I have a feeling that your condition is always resulting else.

  4. #4
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was it, I was giving it a partial path, and it was looking for the full path.


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
  •