Is there a way to update the image of my link when it is clicked on?

Is there a more efficient way to achieve the functionality I want with this code? I currently have an image that changes on hover from a sprite sheet, but I also want it to display a third image when clicked. How can I implement this?

HTML:

<a href="<?php echo base_url('home/linkedin_login')?>" ><img style = "border-radius: 5px;" class="signin-all" src="assets/images/header/blank.png"></a>

CSS:

    [class^="signin-"] {
  display: inline-block;

  vertical-align: text-top;
  background-image: url('../images/signin_sprite.jpg');

  background-repeat: no-repeat;
  *margin-right: .3em;
}
[class^="signin-"]:last-child {
  *margin-left: 0;
}
.signin-all{
background-position: 0px 0px;
   width: 132px;
  height: 37px;
  position: absolute;
}
.signin-all:hover{
background-position: 0px -34px;
   width: 132px;
  height: 34px;
  position: absolute;
}

Answer №1

This task requires the use of JavaScript.

<a href="javascript:void(0)" onclick="updatePic()">
    <img style = "border-radius: 5px;" class="signin-all" src="assets/images/header/blank.png" id="pic">
</a>

<script>
    function updatePic() {
        document.getElementById("pic").src="newImageSource";
    }
</script>

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

Having problems with CSS in your HTML?

Ever since I added <!DOCTYPE html>, my CSS has been causing issues. I realize I should have included the doctype from the beginning, but I didn't. I suspect the problem may lie within the grid (specifically ag-grid) divs, possibly related to th ...

Ways to resolve the form submission issue on ASP.NET Core 3.1 with jQuery integration

I've been encountering issues and I'm looking to the community for help. A year or two ago, a web application was created using ASP.NET Core 3.1 with Razor Pages and C# code behind files. jQuery is also being utilized on the site. The problem li ...

Creating side panels on the left and right using CSS and HTML

I am looking to design a website where users can open sidepanes from both the left and right sides. I am not proficient in JavaScript and would prefer a solution using only CSS and HTML. While browsing, I came across a website that achieves what I want thr ...

Enrich an HTML table using jQuery based on an indentation pattern

                 Overview: Currently, my colleague and I are working on developing an inventory control system using the Django Framework within our department. While most aspects of the system are operational, we are encountering ...

"Transferring an ID from JavaScript to a Laravel PHP script: A Step-by-

i am fairly new to javascript and attempting to send a value to a php script in order to use it in a where clause... Blade html <div class="tab-content blog_tabs"> <div class="tab-pan ...

Rearranging the @use directive in Sass

Here are some style snippets: tokens.scss .text-center { text-align:center; } .bold { font-weight: bold; } @mixin text-style-1 { font-size: 1.2rem; font-weight: bold; } component/card.scss @use "../token.scss" as tokens; .card { @i ...

Dim the shading of a portion of the picture

If you have an image that covers an entire element through CSS like this #myDiv {background-image: url("../images/background.jpg "); background-repeat: no-repeat; background-size: cover; background-position: center;} Now, what if you want to add a gray ov ...

Extend the start day by one day for the checkout option on the Pikaday datepicker

Is there a way to automatically add 1 day to the checkout date when selecting a check-in date? For example, if today is November 8, 2017 and I select November 10 as the check-in date, can the checkout date automatically adjust to November 11? This is the ...

extracting data from checkbox to use in an angular function upon being selected

Currently, I am creating a list of checkboxes with distinct string values: heading, paragraph, list, table, visualtitle. I believe the current approach using (change)="onChange('heading', $event.target.checked) may not be the best way to han ...

What is the best way to ensure that only one accordion tab remains open at a time, preventing it from closing unless a different tab

How can I ensure that only one accordion tab is open at a time, automatically closing any others that are currently open? Here is my current code for the accordion: $('[data-bs-toggle="collapse"]').on('click', function(e) { if ($( ...

Tips for extracting HTML content from JSON data as valid HTML code

I am attempting to extract HTML content from a JSON object response.indexText, which has been validated with JSONLint. { "indexText": "<div id=\"content-home\"><h1> Hello World! <\/h1> <p>Some text.<\/p> ...

Troubleshooting CSS loading issue on iPhone 5 Safari with Responsive Design

I am trying to figure out why my website (Link) is not displaying correctly with responsive design on iPhone5 Safari Browser, even though it works fine on desktop browsers like IE, Chrome, and Safari. It also displays correctly on HTC and Samsung Galaxy de ...

The issue of uploading images with Django is causing a problem for users

I am developing a user personal picture uploading system using the Django framework. The project is named SGV and includes an app called Success to manage user requests. Upon logging in, users are directed to a webpage titled userhome.html where they can u ...

Issue with Navigation menu dropdown not functioning properly on Angular version 12 with Bootstrap 5

I am attempting to integrate bootstrap with Angular through a CDN. Below is the content of my index.html file: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Laboratorio Sigma< ...

Why is my Bootstrap table failing to be responsive?

I'm currently using Bootstrap 4 to incorporate a table into my website and encountering difficulties in making it responsive on mobile phones. Unfortunately, when viewing the table on a phone, it appears very zoomed out and not user-friendly. Can anyo ...

Issue with HTML5 Video Playback on iOS Simulator's Safari Browser

I'm currently testing a website on iPhone and iPad using the iOS Simulator. Interestingly, I have encountered an issue with a video tag that seems to work perfectly fine in all other browsers except for iOS Safari while using the simulator (I don&apos ...

What is preventing the button inside my div element from responding?

I created a button inside of a moving div with a background image and added an animation to the div for movement. However, I encountered an issue where the button did not react as expected. To test this, I added another stationary button which reacted acco ...

Automatically print multiple HTML files with a printer or a Network Printer

I am in search of a way to automatically print multiple HTML files or URLs with just one click from my custom android app. Previously, I utilized the Google Cloud API for this purpose, which involved adding the files to Google Cloud and having them printed ...

Attempting to implement a secondary level of dropdown menu using CSS

As I begin, I want to mention that I have thoroughly reviewed all the sub sub menu questions, but unfortunately, I couldn't find anything that aligns with the code I currently have in place. Any assistance will be greatly appreciated. My current task ...

Placing a table within a div causes the div to expand in width beyond 100%

A situation has arisen where a table with a large number of columns (30 columns) is being affected by the white-space:nowrap style set on each th tag, causing the parent div to stretch unnaturally. How can this issue be resolved and allow for a horizonta ...