Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 282747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:18:54+00:00 2026-05-12T05:18:54+00:00

My image roll over works… But only one way. function heartOver(id) { if(document.getElementById(‘heart’ +

  • 0

My image roll over works… But only one way.

function heartOver(id)
{

    if(document.getElementById('heart' + id).src == 'images/heart.png');
    {
        parent.document.getElementById('heart' + id).src = 'images/unheart.png';
    }

    if(document.getElementById('heart' + id).src == 'images/unheart.png');
    {
        parent.document.getElementById('heart' + id).src = 'images/heart.png';
    }   

}


<img src="images/heart.png" id="heart'.$row['id'].'" alt="Love! width="16" height="16" border="0" onmouseover="heartOver'."('$row[id]')".'; return true;" onmouseout="heartOver'."('$row[id]')".'; return true;">

If i comment out either of the IF statements the other will work but they wont work together…

Note: Tried this with a else if no luck.

Figured it out… Duh: i have if ( ) ; No ; after if…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:18:54+00:00Added an answer on May 12, 2026 at 5:18 am

    Put an else between them – otherwise when the first if evaluates as true, it will cause the second if to be evaluated as true also!

    Here’s a simplified example which also checks the assumption that the img element even exists:

    var img=document.getElementById('heart' + id);
    if (img)
    {
        if(img.src == 'images/heart.png')
        {
            img.src = 'images/unheart.png';
        }
        else if(img.src == 'images/unheart.png')
        {
            img.src = 'images/heart.png';
        }
    } 
    else
    {
         alert("Ooooh! No heart"+id+" element found!");
    }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using CSS Image sprites for roll over effect on a element, the
I'm working on a little image gallery, where you'd roll over a small thumbnail,
I have an image viewer using a js module called cloud zoom. It works
I want my HTML page to load like normal, but I want one section
I’m trying to create a roll over affect for my ImageButton s in my
What's the best way to switch images on mouse-over events ? I want to
i've managed to get a simple animation working so when I roll over my
The code works well, but I have no control of my layout. It toggles
Hi I have an image around 150px wide by 300px deep. When I roll
There is more code to each function, but these are the main lines that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.