Skip to content Skip to sidebar Skip to footer

The == Is Not Working In My If Statement Function

i have a simple function (up) here its an arrow and onclick is should check for image 1 in the div 'gallerymain' and if its there it should show image 2. ELSE if image 3 is displ

Solution 1:

img.src getter (as in img.src == '../img.jpg') returns absolute URL that is http://mysite.dev/img.jpg. img.src setter (as in img.src = '../img.jpg') amends relative URL to absolute.
getAttribute method returns exactly what was assigned. So try this.

if 
    (document.getElementById("gallerymain").getAttribute('src') == 
"../images/gallery/image1.jpg") 
    {
    document.getElementById("gallerymain").src = 
"../images/gallery/image2.jpg"
    }

Post a Comment for "The == Is Not Working In My If Statement Function"