Is there a way to switch my image buttons to a different image when clicked?

In order to create interactive buttons for a website, I designed four unique .PNG images using Photoshop. Two of these images are intended to serve as default buttons, while the other two are meant to be used as "post-click" buttons.

For the default buttons, I assigned separate IDs:

#PlayButton {
    display: inline-block;
    width: 10%;
    position: relative;
    margin-left: auto;
    margin-right: auto;
}

#AboutButton {
    display: inline-block;
    width: 10%;
    position: relative;
    margin-left: auto;
    margin-right: auto;
}

To group these buttons together, I placed them within a class named "Buttons". Here is the code structure:

<div class="Buttons">
    <img src="Play Button.png" id="PlayButton">
    <img src="About Button.png" id="AboutButton"> 
</div>

Answer №1

If you're facing a specific issue, consider implementing a bit of JavaScript to tackle it.

Here's the snippet for the initial image state (prior to button click):

<button onclick="document.getElementById('myImage').src='pic_bulbon.gif'">Turn on the light</button>

And here's the code for the second image post-button click:

<button onclick="document.getElementById('myImage').src='pic_bulboff.gif'">Turn off the light</button>

For further details and examples, check out this resource: JavaScript can modify HTML attribute values. Hopefully, leveraging this explanation will prove beneficial in resolving your issues.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Selecting multiple classes to target specific children individually

Here are the steps you can follow: 1. Include two div elements on a page with identical class names. 2. Insert two elements within each div, such as paragraphs for illustrative purposes. 3. Change the text color of the first paragraph in each div to red. ...

Using AngularJS to handle error validation for dropdowns and select elements that will redirect using the ng

Currently, I am utilizing angularjs's ng-href along with a select HTML element containing ng-model. The ng-href is being used to link to the "selectedItem" from ng-model. However, I have encountered difficulty in validating or displaying an error mess ...

Fixing the Jquery animation glitch triggered by mouseover and mouseout

In my project, I have implemented a small mouseover and mouseout functionality. The challenge I am facing is that I need to keep the mouseout function using animate() instead of css() for specific reasons. The issue arises when I quickly do a mouseover fo ...

"Troubleshooting: Issues with jQuery Counter Functionality

Hey there, I'm new to JavaScript and jQuery! I've got this form set up with Bootstrap's disabled class: Note: the 'disabled' class in bootstrap properly disables and enables the button based on conditions. <form action="" met ...

CSS: Achieving Layered Effect with Child Image Over Parent Background Image

I have set a background image on the .section class in my CSS stylesheet. The background also has an opacity effect applied to it. However, I am facing an issue where the child img (which is a transparent png) is displaying behind the background image of t ...

Positioning the subheading "perfectly beneath the main heading" for a clean and professional look

I'm feeling a bit lost when it comes to tasks like this. While I can easily design an entire website using html and css, I start to question my approach when faced with challenges like these. Could someone offer some guidance? My goal is to have a H1 ...

Specialized dropdown selection function not triggering upon click

I am facing a challenge in triggering an on-click function whenever a user selects an item from a dropdown menu. This is necessary because the default styling of the dropdown cannot be modified. My objective is to update a field with the selected item&apo ...

What methods can be used to prevent users from seeing the URL when submitting this form?

My form has numerous fields that I need to submit... When I submit these fields, I use the POST method to conceal the actual variables being passed to the PHP page. Unfortunately, I am unable to eliminate the complete link. Switching from GET to POST su ...

PHP does not properly interpret quotation marks when passed from an HTML form

My current setup involves a simple HTML form with a submit button that triggers my PHP script to process the input. However, I've encountered an issue where my PHP code fails to recognize the quotation mark when using str_replace function. Below is a ...

Enhancing the functionality of angular-messages is impacting the overall design of

Displaying here is the current state of my login form: https://i.sstatic.net/EMcjF.png However, subsequent to upgrading angular-message to version 1.4 and higher, the layout transforms into this: https://i.sstatic.net/vVBHf.png Sharing my source code f ...

Introducing Row Offset Enhancement

I am working on a code to create a custom "table" because I require some more intricate features that a regular table cannot provide. <div class="container"> <cfloop index="x" from="1" to="5"> ...

What is the best way to utilize JSONP to display an entire HTML code with an alert?

When I attempt to use cross-domain ajax to retrieve the entire HTML page code, I keep receiving a failed message. The console log shows: "Uncaught SyntaxError: Unexpected token <" Below is my AJAX function: function fetchData(){ var url = documen ...

The connection between the layout of dropdown menus and the way data is handled in forms

I have discovered three different methods for creating dropdowns that can be used in forms: 1) Utilizing HTML with "form-dedicated" attributes such as select and option value="" 2) Implementing the Bootstrap framework with div classes like "dropdown", Butt ...

Create a surplus of information

I'm currently working on a project where I need to replicate all the entries multiple times and then have them spin and gradually land on a color. However, I'm encountering an issue with duplicating the colors without increasing the width. How ca ...

Json data integrated dropdown menu

I have successfully retrieved data from a Json array and displayed it in a dropdown list. However, I am facing an issue where I want to only show the name of the city instead of both the name and description. If I remove cities[i]['description'], ...

Can using display: none impact the SEO of a website's navigation menu?

Is there a difference in SEO impact between using display:none with CSS and using display:none with jQuery for menus? Appreciate the insights! ...

What is the best way to achieve this smooth scrolling animation on the page?

While browsing the website , I noticed a unique page scrolling effect that caught my eye. Unsure if they were using default bootstrap code or their own custom code, I was intrigued by how it worked. I attempted to find similar effects online but struggled ...

Why is it that this JavaScript isn't working as intended in the popup form?

</br> s_foot"> * use ajax.jquery as control event. like $("#save").click(function(){.....}); <script type="text/javascript>" var wp; var position; var pid; var product_name; var production_date; In this script, I am attempting to re ...

What is the best way to leverage a webbrowser control for design purposes while keeping the functionality in C#?

Observing some apps, it seems they utilize HTML/CSS/Javascript for styling - a much simpler approach compared to crafting the same thing natively. However, these apps have their logic written in C#. Sadly, I am clueless on connecting the two. Research yiel ...

The Harp server generates excessive white space within HTML documents

Running a blog on Harp has been smooth sailing, except for one issue that I can't seem to figure out. The project utilizes EJS and the problem lies in the outputted HTML containing excessive whitespace. I've attempted to minimize it, especially w ...