I am looking to update the image source when clicking on it using only CSS, something along the lines of:
img:active {
}
I am looking to update the image source when clicking on it using only CSS, something along the lines of:
img:active {
}
If you want to achieve this effect, you can utilize the element replacement feature of the content property.
However, keep in mind that using this technique may result in certain accessibility features not being set properly, potentially leading to information being lost for some users. Depending on the context and audience, this could have legal implications.
To ensure better accessibility, consider setting a tabindex or enclosing the image in a button element.
It's important to note that the :active pseudo-class represents "While being clicked on," not "After being clicked on." CSS does not offer an "after being clicked on" pseudo-class, though :focus may serve as a workaround in certain scenarios.
img:active {
content: url(http://placekitten.com/200/200);
}
<img src="http://placekitten.com/g/200/200" alt="">
Modifying the source of an image using only CSS is not possible. However, one workaround is to set the image as a background for its parent element and then change the background using CSS like this:
.image-container { background-image: url('myurl...')} ;
.image-container:active {background-image: url('anotherurl...')}
I hope this solution works for you.
This webpage was built using HTML. I incorporated javascript into it. I assigned the content of the HTML element h1 to a variable named oj using the method getElementById. In an online tutorial, it mentioned that oj should behave like an array. So, why ...
Having a modal with a form (using Bootstrap-Vue and Vue2) where each row contains two fields. If the user does not input a valid value into a field, the state of that field turns false, causing the box to be highlighted in red and displaying an error messa ...
I am attempting to make changes to my app.scss file in my Symfony 4 project. Unfortunately, the background-color property is not being applied as expected. body { background-color: #ccccff; } In my base.html.twig file, I have the following structure: ...
I am currently facing a challenge with converting inline JS to jQuery. My goal is to eliminate all inline onclick events and instead target them by class. HTML - checkbox <td class="center"> <?php if ($product['selected']) { ?> ...
I'm struggling to add text under the images in this slider. The functionality is simple, but I can't figure it out. I might have to rewrite it. Here's the HTML and JS: <div id="look-book-scroll"> <a href="javascript:;" id="lookbo ...
As I work on developing a HTML5 canvas-based game within a WebView of an existing application, I encounter a puzzling issue. Upon the initial run of the game, everything seems to be in order - logs indicate that it's ready and running, yet nothing is ...
Is there a way to make a line of text quickly fade in, stay visible for 5 seconds, fade out quickly, then have a different line of text quickly fade in, stay for about 5 seconds, fade out quickly, and repeat this process infinitely in AMP? I tried using ...
I have a query regarding building a website that can be started via PowerShell. The PowerShell HTML code I am using is: $proxys = "" foreach ($email in $ADObj.proxyAddresses){ $proxys += "<button id='$email' name='alias&apo ...
Challenge: How can I ensure that the code within the if statement only executes when the screen width exceeds 767px, and does not work if it is less than 767px? Using jQuery: $(document).ready(function() { $(window).resize(function() { if ($( ...
Currently, I am working on a jQuery animation where clicking on a tile should display its information by hiding all other tiles and showing its details. While I have implemented .stop() to prevent queuing issues, I encountered a problem with the transition ...
Is there a valid reason for this question to persist? I'm considering removing it. ...
Is there a way to achieve the combination of fixed and fluid width columns using Twitter Bootstrap alone, similar to this example? The HTML and CSS in the example make it seem simple. But can this be done solely with Bootstrap? ...
I have been attempting to clear the txtSubTotal text box upon clicking the PROCEED button, but it seems that my efforts have been in vain despite trying various code examples, including those from SO. btnProceed/HTML <input type="submit" name="btnProc ...
I am looking to create a unique feature in HTML where multiple tabs can be opened with different URLs using one link. While I know how to open one link in a new tab, I am unsure of how to simultaneously add another URL that will open up in a separate tab ...
I have recently developed a BMI calculation web application where users can input their details and calculate their BMI. However, I am facing an issue with displaying the records on the webpage. Below is the code snippet for the application: app.py f ...
In my current project, I am utilizing Angular UI Grid. The grid automatically resizes itself so that all columns fit within a specific div horizontally. While this feature works well initially, it becomes problematic when there are more rows than can fit ...
I have a task to create a table for 10 different projects (Jupiter, Uranus, Saturn, etc..) with an individual comment section for users to add updates. Each row has its own "add record" button, but I want to implement a single "submit" button at the bottom ...
I am facing a challenge in creating a table where the first column is fixed while the rest of the columns are scrollable horizontally. Although I was able to implement this successfully, it does not seem to work when integrated into my website. Whenever ...
My goal is to create a background reveal effect using JavaScript by increasing the percentage. The effect should start from the center and expand outwards in all directions. Issue: The percentage increase currently affects only the bottom and not the top ...
Imagine a page showcasing links to detailed pages in the form of cards. Each card features an image, a heading, a view button, and a save button. Here's a visual representation: +-----------------+ | | | IMAGE | | ...