0

I am using this JavaScript function in order to change image on click, but it is doing refresh all the time and go back to the original image.

this is the code I am using;

function showImage1() {; 
    document.getElementById('Image5').style.visibility = 'visible';
    document.getElementById('Img1').style.visibility = 'hidden';
}

<div>
    <input ID="Button1" type="image" src=" Resources/Icons/benefitBtn.png" OnClick="showImage1();"/>
</div>

Any suggestion please?

2
  • 2
    There is no jQuery in your example. I edited the title, question, and tags to reflect that. Commented Mar 23, 2012 at 15:56
  • Can you clarify your question? What does "doing refresh all the time and go back to the original image" mean? Commented Mar 23, 2012 at 15:57

2 Answers 2

2

<input ID="Button1" type="image" src="Resources/Icons/benefitBtn.png" onClick="showImage1();return false;"/>

Adding return false should stop any submit nature. If I understood correctly.... :)

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

 function toggleImage(elementToShow,elementToHide){
    $("#" + elementToShow).show();
    $("#" + elementToHide).hide();
 }

 <div>
 <input ID="Button1" type="button" class="yourButtonClass" OnClick="showImage1('Image5','Img1');"/>
 </div>

 set your button's background image in your stylesheet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.