What is the method to show text exclusively upon hovering the mouse?

Here is a sample that I'm working with:

link

HTML CODE:

SED PERSPICIATIS

Sed ut perspiciatis unde omnis iste natus error sit
voluptatem accusantium doloremque laudantium,
totam rem aperiam, eaque ipsa quae ab illo inventore
veritatis et quasi architecto beatae vitae dicta sunt
explicabo.

<div class="col-md-4 tab-bottom">
    <div class="tab-bottom-img"><img width="380" height="380" src="http://dg-design.ch/bagel/wp-content/uploads/2016/02/1-380x380.png" class="attachment-news wp-post-image" alt="1"> </div>
    <div class="tab-bottom-content">
        <div>
            <p class="title_bottom">SED PERSPICIATIS</p>
            <p class="content_bottom"></p><p>
                Sed ut perspiciatis unde omnis iste natus error sit<br>
                voluptatem accusantium doloremque laudantium,<br>
                totam rem aperiam, eaque ipsa quae ab illo inventore<br>
                veritatis et quasi architecto beatae vitae dicta sunt<br>
                explicabo.
            </p>
            <p></p>
        </div>
    </div>
</div>
<div class="col-md-4 tab-bottom"gt;
    <div class="tab-bottom-img"><img width="380" height="380" src="http://dg-design.ch/bagel/wp-content/uploads/2016/02/1-380x380.png" class="attachment-news wp-post-image" alt="1"> </div>
    <div class="tab-bottom-content">
        <div>
            <p class="title_bottom">SED PERSPICIATIS</p>
            <p class="content_bottom"></p><p>
                Sed ut perspiciatis unde omnis iste natus error sit<br>
                voluptatem accusantium doloremque laudantium,<br>
                totam rem aperiam, eaque ipsa quae ab illo inventore<br>
                veritatis et quasi architecto beatae vitae dicta sunt<br>
                explicabo.
            </p>
            <p></p>
        </div>
    </div>
</div>

CSS CODE:

.col-md-4 {
    width: 33.33333333%;
}
.tab-bottom {
    position: relative;
    height: 400px;
    float:left;
}
.tab-bottom-img {
    width: 100%;
    position: absolute;
    top: 50%;
    height: 100%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.tab-bottom-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

JS CODE:

$(".tab-bottom").bind('mouseover',function(event){
    $(this).find("tab-bottom-content").css("display", "block");
});
$('.tab-bottom-img').bind('mouseleave', function(e) {

});

I want the text in the div tab-bottom-content to be displayed only when the mouse is over.

I have tried using the script above but unfortunately it is not working as expected

Can anyone help me solve this issue?

Thank you in advance!

Answer №1

To tackle this, I recommend using CSS instead.

You can view an example here

Sample HTML code:

<div class=tab-bottom>
  <div class=tab-bottom-content>
     Test
   </div>
</div>

CSS:

.tab-bottom{
  border: 1px SOLID #F00; /* Used for visual representation */
  width: 200px;
  height: 200px;
}

.tab-bottom.tab-bottom-content{
  display: none;
}
.tab-bottom:hover .tab-bottom-content{
  display: block;
}

No JavaScript or jQuery required in this instance :)

Answer №2

To start, it is recommended to conceal .tab-bottom-content initially by utilizing display: none like so.

.tab-bottom-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none
}

Next, incorporate the following jQuery code. Ensure to include the period . before tab-bottom-content, as it was omitted initially.

$(".tab-bottom").mouseover(function(event){
    $(this).find(".tab-bottom-content").show(300);
}).mouseleave(function(e) {
    $(this).find(".tab-bottom-content").hide(300);
});

Answer №3

Make sure to include '.' in the .find("tab-bottom-content")

$(".tab-bottom").on('mouseover',function(event){
    $(this).find(".tab-bottom-content").show(300);
});
$('.tab-bottom').on('mouseleave', function(e) {
    $(this).find(".tab-bottom-content").hide(300);
});

Check out this pen for reference

Don't forget to add CSS as well

.tab-bottom-content {
    display:none;
 }

You can also use inline styles to initially hide the 'tab-bottom-content' content

Answer №4

To make the text appear when hovering over the tab-bottom-content div, you can initially set its opacity to 0, and then change it to 1 in the :hover pseudo-selector class. You can also add a smooth transition effect for a more polished look. Here's how you can achieve this:

.tab-bottom-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid black;
  opacity: 0;
  transition: opacity .4s ease-in;
}

.tab-bottom-content:hover {
  opacity: 1
}

Feel free to test it out on 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

Creating a 3-column div with varying sizes of text in another div at the center position

I am attempting to create a 3-column layout using only DIVs, but I am facing some challenges. If I were to use tables in the traditional HTML 4 way, I could achieve this: <div style="width:100%"> <table width="50%" align="center"> ...

What is the method to ensure that flexbox takes into account padding when making calculations?

There are two sets of rows displayed below. The first row contains two items with a flex value of 1 and one item with a flex value of 2. The second row contains two items with a flex value of 1. As per the specification, 1A + 1B = 2A However, when ...

Retrieve all information about orders that include a product purchase using MySQL

My goal is to generate a list of all items that have been purchased in orders containing a specific item. For example, I would like to search for all orders that include tomato ketchup and display the products from these orders. I am looking to identify w ...

Updating objects in Angular 8 while excluding the current index: a guide

this.DynamicData = { "items": [ { "item": "example", "description": "example" }, { "item": "aa", "description": "bb" }, ...

Using React to Filter cards according to the selected value from an Autocomplete feature

I'm currently developing a React application that utilizes Material-UI's Autocomplete component to filter cards based on selected car brands. These cards represent various models, and the goal is to update them when a user picks a brand from the ...

Click on the "bootstrap" tab to access an external website

Greetings, I find myself in this particular situation, <ul id="myTab" class="nav nav-tabs" role="tablist"> <li class=""><a href="#Tab1" role="tab" data-toggle="tab">TAB1</a></li> <li class="active"><a href="# ...

Rotate clockwise function for navItem Title in Wheelnav.js

Can I rotate the title clockwise for specific navItems only? I have discovered that the following code affects all of them: wheel.titleCurved = true; wheel.titleCurvedClockwise = true; ...

Using percentages for CSS alignment and adjusting element widths

Greetings everyone! I have been struggling to align two divs - one on the right with a width of 30% and the other on the left with 70%. Despite my efforts, I have not been able to find a solution. I am hopeful that someone here can assist me. My setup inv ...

Discovering the variance among two arrays of dates in JavaScript

I am attempting to identify the variance between two sets of dates stored as arrays, and then segregate all distinct dates into a separate array for future use. Additionally, I have a specific functionality in mind. I have a variable called diffDates. It n ...

Utilizing Prisma's Create Object to Store Return String from Imported Function in Database

In my application, I am utilizing Typescript and have created a test to populate a database using Prisma ORM. Within this test, there is a function that returns a string: const mappingPayload = (data: any) => { let pay = [] const payload = data[0] // ...

How can we export data to excel using react-export-excel while ensuring certain columns are hidden?

Greetings! I believe the title gives you a clear idea of my dilemma. When exporting data, there are no errors - my goal is to hide the Excel column when the checkbox is unchecked or false, and display it when the checkbox is checked or true during export. ...

Removing a row by its id in VueJs using the splice method

After successfully deleting an item from the database, I am facing an issue where the item is not being removed from the list. I understand that I should use the index to splice the item from the list. However, using the index means I cannot pass the it ...

Executing asynchronous promises within an asynchronous promise using the .join() method

I am currently utilizing node/express, MySQL, and Bluebird for my project. When handling client requests, I am performing async database operations. After the initial database operation callback, I need to carry out some calculations before executing two ...

Steps to reveal a div element using the fadeIn() method

I have hidden a div using display:none, like this: <div id="mydiv" style="display:none">My Text</div> I tried to make the div appear using the fadeIn() method: $("#mydiv").fadeIn(); However, it did not work as expected and the div remained ...

During the rendering process, the property "quote" was accessed, however, it is not defined on the current instance. (Vue.js)

Every time I try to retrieve data from the kanye API, I encounter this error message: Property "quote" was accessed during render but is not defined on instance. Below is the code snippet that triggered the error: <template> <div> ...

Issue with Vuetify server side Datatable filtering in Vue.js未解决

I'm currently utilizing vuetify to handle my datatable functionality, including pagination and sorting. However, I've encountered an issue with the search filter. Although the response data from the search filter is correct, it's not getting ...

Is there a way to display all articles within an array while utilizing a computed property to sort through outcomes on VueJS?

I am currently utilizing VueJS to display a collection of articles. Additionally, I have integrated filters that utilize checkboxes and a computed property to refine the display of articles based on the selected tag. However, I am interested in incorporat ...

What is the best way to link a button to a form in Angular?

I'm currently utilizing Angular 6.x and I am looking to link a submit button that is located outside of the form in the DOM. Essentially, I want to achieve something similar structurally to this: <button type='submit' form='myform&a ...

What is the best approach: Loading all database results at once or making multiple requests?

Looking to refine a vast database with these specific columns: Name - Maximum Height - Minimum Height - Range - Maximum Angle - Minimum Angle The goal is to filter the data based on user-inserted criteria, such as if a user inputs a maximum height of 80c ...

Enable swipe functionality for mobile users

Looking to make the code below swipable on mobile devices. Any suggestions or resources to achieve this would be greatly appreciated! <script> var links = document.querySelectorAll(".heart"); var wrapper = document.querySelector("# ...