What is the secret to getting the rollover to stay in place after being clicked?

I have a navigation made up of buttons that use image sprites. I want the buttons to remain in a "rolled over" state once clicked, even when navigating to different pages. They should revert back to normal when clicked again.

Although I am new to JavaScript, I believe there must be a way to achieve this functionality.

An example button is shown below:

<a class="contact" href="#" >Contact</a>

Below is the CSS used to create the rollover effect:

a.contact {

display: block;  
width: 30px;  
height: 31px;
margin-right:39px;
float:right;
background: url(../img/navcontact.png) no-repeat bottom;
text-indent: -10000px;     

}

a:hover.contact {

background-position: 0 0;  

}

Answer №1

To achieve this, implement jQuery. A live demonstration can be found at this link.

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

Pick the initial child of a specified type within an element

I am trying to target the first <div> child under the <body>, excluding any other elements. While I could assign an ID to the element, I am interested in finding a more universal solution for this scenario. For example, in a basic setup like ...

Embed JavaScript locally within an iframe HTML

When attempting to add HTML code within an iframe to showcase data, everything works as expected. However, the issue arises when trying to include any JavaScript within the iframe, as it doesn't seem to be recognized locally. Below is the example cod ...

Can one deduce the generic type from within a string template literal?

I have a piece of code that achieves my desired outcome, but I want to avoid explicitly specifying the generic it requires. type EventGroup = { actions: "run" | "save" other: "bla" } export type EventType<T extends keyof EventGroup> = `${T}/${Ev ...

Is it possible to postpone sending a message on Discord until a certain event has been successfully completed?

After the User leaves the Discord, I attempted to create a RichEmbed Message that would include a random GIF from Giphy. The GIF was meant to be generated using the getGiphyPic() function with the help of this node module: https://github.com/risan/giphy-ra ...

Concentrate and select non-interactive elements with your mouse

Is it possible to set tab index on non-form elements like the div tag? I tried using tab index, but when the div is focused and the enter button is tapped, the ng-click event associated with the div tag is not triggered. <div tabindex="0" role="butto ...

What's the issue with this jScrollpane?

Why isn't Jscrollpane working with Asp.Net? It functions perfectly on a normal html page, but when I transfer the same code to my .aspx page, only standard scrollbars appear! Check out my successful JSFiddle here! However, on my aspx page, the code ...

Having trouble getting Jquery UI draggable to work on your Wordpress site?

<script type='text/javascript' src='.../wp-admin/load-scripts.php?c=1&amp;load%5B%5D=jquery-core,jquery-migrate,utils,plupload&amp;ver=4.6.1'></script>//Loaded jQuery v1.12.4 <script type='text/javascript&apo ...

Trouble encountered while configuring and executing Electron combined with React, Typescript, and Webpack application

I am currently in the process of migrating my Electron application from ES6 to Typescript. Despite successfully building the dll and main configurations, I encounter a SyntaxError (Unexpected token ...) when attempting to run the application. The project c ...

What is the best way to generate separate instances of a React element for different copies?

Just started learning React. I'm working on creating a set of 12 range sliders, arranged in two columns of six each. Each column is defined separately and has its own instance of the slider. The react-slider package is used for each range slider, wit ...

I am converting a class component to a functional component within a React-Redux-Firebase project

I am currently in the process of rebuilding this component. Check out the updated code here Also, take a look at the project actions script here However, I'm facing an issue with rewriting mapStateToProps and mapDispatchToProps functions. The error ...

index.js: Module 'react-native-reanimated/plugin' not located

> Error: Module 'react-native-reanimated/plugin' not found in index.js To resolve this problem, I commented out the plugins array containing ['react-native-reanimated/plugin'] in the code snippet below: module.exports = function(api ...

Protecting against overflow for text inside a container that changes when hovered over

There is text displayed on top of an image within a div container that functions as a link. <a href="https://link.com" style="color:white"> <div class="thumbnail"> <img src="image.jpg" clas ...

Juicer- Setting restrictions on the frequency of posts

How can I limit the number of posts displayed using the react-juicer-feed component? import { Feed } from 'react-juicer-feed'; const MyFeed = () => { return ( <Feed feedId="<feed-id>" perPage={3} /> ...

Delete line breaks only within a particular field, leaving the rest of the text

I've been tasked with cleaning up data in a MongoDB collection that contains addresses and generic customer contact information. The data sometimes includes carriage returns, which can cause issues when loading the data into a MySQL table. My solutio ...

`Positioning Divs Correctly over Images with jQuery UI`

I have a collection of images arranged in a table (with each image housed within its own td). There is also a div that contains various operations that can be executed on an image. As I hover over an image, the div should be displayed on top of it. Current ...

A function that retrieves the empty values from an array and returns undefined if there

After undergoing a time-consuming process, the sample below shows that the array values are returned empty. function myFunction() { let myArray = []; let pastArray = [1, 2, 6, 7, 8, 1, 9, 6, 0] pastArray.forEach(item =>{ setTimeout(function(){ myA ...

JavaScript regular expression to find words, excluding words enclosed by forward slashes

I have a regular expression that is functional in PHP: (?<![\/?$])\bfoo\b Now, I am trying to adapt it for use in JavaScript. Specifically, I want it to match the following patterns: foo - need this <div>foo</div&g ...

Storing a JWT in the client's browser that survives a browser restart in Next.js

I'm in the process of developing an application that requires a JWT to be stored by the client for at least 24 hours. This may seem unconventional, but my project involves incorporating something known as "Litprotocol" which deals with decentralized a ...

Is there a way to remove or replace the existing polyline to ensure that only one is displayed at a time?

My goal is to have a single line drawn from the closest marker to a static position. I can determine which marker is the closest by sorting the distances, but if a new marker is added and is closer than the previous closest one, a new polyline is drawn wit ...

Error encountered while trying to store a JSON object in local storage

When attempting to insert a JSON in localStorage, I am encountering the error Unexpected token ~ in JSON at position 3 during the parse process. Here is how I am inserting the data into localStorage: localStorage.setItem( "users", `"[\"~#iM& ...