Show different text or letter when hovering

Is there a way to hide one letter and display another in a link, with a different style on hover? For example:

This is a...

...regular link.

And this is a...

...hovered link.

Any ideas on how to make this happen? Thank you.

Edit: Just to clarify — I'm looking to change specific letters (i ➛ î, e ➛ ê) and apply a style change on hover, without altering the entire link structure.

The code snippet shared by the individual who asked this question

$('.class').hover(function()
{
$(this).data('i', $(this).text());
$(this).text("î");
},
function()
{
$(this).text($(this).data('i'));
}
);

It almost provided the solution. However, it currently changes the entire link rather than just the letters.

Answer №1

That was quite an entertaining experience! Here's a little fun activity involving random letter substitutions with accents. It might be a bit too intense for your liking, but feel free to customize it by removing the letter substitutions you don't want.

var diacriticsMap = [ { 'base':'A', 'letters':[ '\u0041','\u24B6','\uFF21','\u00C0','\u00C1','\u00C2','\u1EA6','\u1EA4','\u1EAA','\u1EA8','\u00C3','\u0100','\u0102','\u1EB0','\u1EAE','\u1EB4','\u1EB2','\u0226','\u01E0','\u00C4','\u01DE','\u1EA2','\u00C5','\u01FA','\u01CD','\u0200','\u0202','\u1EA0','\u1EAC','\u1EB6','\u1E00','\u0104','\u023A','\u2C6F']}, {'base':'AA','letters':['\uA732']}, {'base':'AE','letters':['\u00C6','\u01FC','\u01E2']}, {'base':'AO','letters':['\uA734']}, {'base':'AU','letters':['\uA736']}, {'base':'AV','letters':['\uA738','\uA73A']}, {'base':'AY','letters':['\uA73C']}, {'base':'B', 'letters':['\u0042','\u24B7','\uFF22','\u1E02','\u1E04','\u1E06','\u0243','\u0182','\u0181']}, {'base':'C', 'letters':['\u0043','\u24B8','\uFF23','\u0106','\u0108',...
// and so on
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<ul>
  <li><a class="flip-me" href="#">Unlocking ancient secrets</a></li>
  <li><a class="flip-me" href="#">Discovering hidden realms</a></li>
  <li><a class="flip-me" href="#">Exploring mystical lands</a></li>
  <li><a class="flip-me" href="#">Unraveling enchanted tales</a></li>
</ul>

Answer №2

$('#box').click(function(){
  $(this).toggleClass('bold');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="box">Click Me</div>

Answer №3

With the use of jQuery, achieving this task is simple. See below for a sample code snippet.

HTML CODE

<p class="c-hover">Normal Text</p>
//assign the "c-hover" class to the desired element

JS CODE

$('.c-hover').hover(function(){
 $(this).text('Hover Text'); //displayed text on hover
},function(){
 $(this).text('Normal Text'); //original text when not hovering
});

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

Why must the sidebar be displayed horizontally on the smartphone screen?

I've been struggling to make the sidebar menu on my smartphone display horizontally with icons at the top and text at the bottom. I've tried using flex and other methods, but it still doesn't work sideways. Am I missing something? const s ...

Exploring feature detection in jQuery version 1.4

Is there a way to use feature detection to determine if the browser is Firefox, IE (excluding IE6), Opera, Chrome, or Safari? ...

Try utilizing an image to hold text content rather than a traditional div container

I am seeking help with displaying a brief image description at the bottom of an image. Currently, the display looks like this: https://www.bootply.com/render/Gwde8WHtot However, I would like the green background to align with the actual image rather than ...

jQuery fails to apply a class if the input fields are not empty

I am currently working on a function that displays a login button only when both input fields are not empty. However, for some reason, jQuery seems to be giving me trouble with this task. Despite checking and ensuring that I am using the correct and updat ...

Using jQuery and JavaScript: The recursive setTimeout function I created accelerates when the tab is no longer active

I am facing a unique challenge with my jQuery slideshow plugin that I'm currently developing. Although the code is running smoothly, I have observed an issue where if I leave the site open in a tab and browse elsewhere, upon returning to the site (us ...

Tips on avoiding the collapse of the right div when positioned under a left float in a full page layout

Trying out a full page layout for the first time, with a left div serving as a block style nav. #admin_nav { width: 230px; height: 100%; background-color: #f9f9f9; border-right: 1px solid #ddd; float: left; } The content is on the rig ...

Steps to fix the issue: Unhandled Type Error: t.addLayer is not a recognized function

I've encountered a bit of difficulty with an error that I can't seem to figure out. I'm currently working on adding a geoJSON layer to my Leaflet Map, specifically a multi-polygon representing country borders. To achieve this, I'm using ...

django is not able to load staticfiles from the statifiles_dirs directory

I have placed my style.css in the directory appname/static/appname/. In my settings.py, this is what I have: STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static/"), ) When I try to load it in my base.html like t ...

Demonstrating the concept of a hierarchical matrix in D3: A detailed

Looking for a unique visualization that combines the concepts of a hierarchical tree and a Matrix in D3. The vision is to have collapsible x and y-axes, resembling a tree structure (e.g. similar to http://bl.ocks.org/mbostock/1093025, , or http://bl.ocks. ...

Creating an overlay effect when hovering over an image

Recently, I've been working on a gallery of photos that showcases different individuals. My goal is to have information about each person displayed when their respective photo is hovered over - including their name and role. .gallery { position: ...

What is the process for setting an AMP-video as a full-page background?

My homepage features a captivating hero video in the background, but I've encountered an issue where the AMP video does not scale properly to fit the screen on mobile devices. Here's the code snippet causing the problem: <amp-v ...

Tips for deciding on the appropriate CSS for an Angular 6 navbar component

I am currently working on an angular 6 application where users are assigned different roles that require distinct styling. Role 1 uses Stylesheet 1, while Role 2 uses Stylesheet 2. The Navbar component is a crucial part of the overall layout structure of ...

Steps to create a hover effect that alters the appearance of another chosen "element"

For instance, I have two classes named A and B. I want to be able to change the appearance of B when I hover over it, such as its color or size. I am unsure if this can be achieved using CSS and the onmouseover event. I am including a snippet of code that ...

"Unexpected issue with jQuery AJAX Post functionality on a shared server causing data not to

I'm currently facing an issue with my code that allows comments to be added to a php page without needing to refresh the page. While everything is functioning properly on localhost, I encountered a problem when testing it on my justhost account. The ...

Exploring how to utilize AJAX for data filtering within the Laravel framework has piqued

The current controller is returning a value even when the fields are empty. I need to display a message if all the fields are empty. Controller public function filterSearch(Request $request){ $obj = (new VaccinationInfo)->newQuery(); if($req ...

Converting JSON data to an array using an Ajax request

I am currently working on an HTML project where I have the following code: <div id="main"> <div id="blogcont"> <p></p> </div> <button class="nvgt" id="prev" >Previous</button> <button ...

Here's a solution to prevent the "jump" effect when hiding elements in a navbar

Currently, I am facing an issue with my h5 elements within the navbar when scrolling. I am using Bootstrap 4 and jQuery for this project. The problem arises in my navbar where there are four sets containing an icon, followed by an "h5" and then a "p" elem ...

Jquery animated auto

One thing I've been pondering is whether it's possible to create a continuous glowing effect on an object using JQuery. Is there some sort of auto animation feature that can iterate through fadeIn and fadeOut functions? If such a function exists, ...

Align the text characters vertically within a word or sentence

I currently have a logo that consists of lines and text. I would like to create a similar version using CSS for my website. https://i.sstatic.net/vxS8Z.png My goal is to have the letters "T - S o N" appear in one line with the letter "o" positioned verti ...

Navigation dropdown menu with the latest Bootstrap 4 features

Attempting to recreate the design from Codepen using Bootstrap 4. The current progress can be viewed in this Codepen (drop down with 2 columns), which is assisting with online tutorials. Here's the HTML for the Navbar: <nav class="navbar navbar- ...