Switching out text when hovering with Jquery or JavaScript

Is there a way to use jQuery or JS to make the text and icon disappear when hovering over a div, and replace it with "Read More"? I've looked at some guides but they only remove one line of text instead of clearing the entire div and displaying "Read More" centered on mouseover. Any suggestions on how to achieve this? The divs are actually horizontal on the page, not sure why they appear vertical here.

.feature-container {
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 9;
  width: 100%;
  display: inline-block;
}

.feature-box {
  background: #fff;
  text-align: center;
  padding: 40px 30px;
  position: relative;
  width: 25%;
}

.feature-box i {
  font-size: 50px;
  margin-bottom: 15px;
  cursor: pointer;
}

.feature-box:hover {
  background: #208541 !important;
  color: #f6f6f6;
}

.feature-box.dark {
  background: #f6f6f6;
}
<div class="feature-container">


  <div class="feature-box-container feature-slider">
    <div class="feature-box">
      <i class="ion-ios-list-outline"></i>
      <h4>Content</h4>
      <p>Effective learning methodology that focuses on concepts and understanding of AICPA blueprints.</p>

    </div>
    <div class="feature-box dark">
      <i class="ion-ios-cog-outline"></i>
      <h4>Customization</h4>
      <p>Adaptive content for a custom learning experience and individualized delivery through AdaptaPASS.</p>
    </div>
    <div class="feature-box">
      <i class="ion-help"></i>
      <h4>Support</h4>
      <p>Direct access to our instructors and CPAs, by phone, email, or via our student-only message board.</p>
    </div>
    <div class="feature-box dark">
      <i class="ion-social-usd-outline"></i>
      <h4>Value</h4>
      <p>Everything you need -- for less. Our course bundle costs hundreds less than competitors.</p>
    </div>
  </div>


</div>

Answer №1

Here's a quick way to start off. I'm utilizing the .css('visibility', 'hidden'); method to only hide text without affecting box height adjustments. If you require something different (like using CSS for height fixes), you can make use of .hide() and .show() functions to toggle text visibility during mouse events.

$('.feature-box').on('mouseenter', function(){
  $(this).find('i, h4:not(.rm), p').css('visibility', 'hidden');
  $(this).find('h4.rm').css('visibility', 'visible');
});

$('.feature-box').on('mouseleave', function(){
  $(this).find('i, h4:not(.rm), p').css('visibility', 'visible');
  $(this).find('h4.rm').css('visibility', 'hidden');
});
.feature-container {
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 9;
  width: 100%;
  display: inline-block;
}
h4.rm{ visibility: hidden; }
.feature-box {
  background: #fff;
  text-align: center;
  padding: 40px 30px;
  position: relative;
  width: 25%;
}

.feature-box i {
  font-size: 50px;
  margin-bottom: 15px;
  cursor: pointer;
}

.feature-box:hover {
  background: #208541 !important;
  color: #f6f6f6;
}

.feature-box.dark {
  background: #f6f6f6;
}
<link href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="feature-container">


  <div class="feature-box-container feature-slider">
    <div class="feature-box">
      <i class="ion-ios-list-outline"></i>
      <h4>Content</h4>
      <h4 class="rm">Read more</h4>
      <p>Effective learning methodology that focuses on concepts and understanding of AICPA blueprints.</p>

    </div>
    <div class="feature-box dark">
      <i class="ion-ios-cog-outline"></i>
      <h4>Customization</h4>
      <h4 class="rm">Read more</h4>
      <p>Adaptive content for a custom learning experience and individualized delivery through AdaptaPASS.</p>
    </div>
    <div class="feature-box">
      <i class="ion-help"></i>
      <h4>Support</h4>
      <h4 class="rm">Read more</h4>
      <p>Direct access to our instructors and CPAs, by phone, email, or via our student-only message board.</p>
    </div>
    <div class="feature-box dark">
      <i class="ion-social-usd-outline"></i>
      <h4>Value</h4>
      <h4 class="rm">Read more</h4>
      <p>Everything you need -- for less. Our course bundle costs hundreds less than competitors.</p>
    </div>
  </div>


</div>

Answer №2

If you want to achieve this, my suggestion is to utilize a CSS-only solution.

Create a new div, position it using absolute, and then simply display it on hover of the feature-box.

For the positioning to work correctly, make sure the feature-box has position: relative set, while the new div should have a higher z-index and top: 0; properties defined.

Answer №3

If you need to accomplish this, you can utilize css as shown below.

.feature-container {
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 9;
  width: 100%;
  display: inline-block;
}

.feature-box {
  background: #fff;
  text-align: center;
  padding: 40px 30px;
  position: relative;
  width: 25%;
  display: inline-block;
}

span.read-more {
  display: none;
  font-weight: bold;
  position: absolute;
  z-index: 10;
  top: 0;
}

.feature-box:hover p {
  display: none;
}

.feature-box:hover span.read-more {
  display: block;
  position: relative;
}

.feature-box i {
  font-size: 50px;
  margin-bottom: 15px;
  cursor: pointer;
}

.feature-box:hover {
  background: #208541 !important;
  color: #f6f6f6;
}

.feature-box.dark {
  background: #f6f6f6;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="feature-container">


  <div class="feature-box-container feature-slider">
    <div class="feature-box">
      <i class="ion-ios-list-outline"></i>
      <h4>Content</h4>
      <p>Effective learning methodology that focuses on concepts and understanding of AICPA blueprints.</p><span class="read-more">read more</span>

    </div>
    <div class="feature-box dark">
      <i class="ion-ios-cog-outline"></i>
      <h4>Customization</h4>
      <p>Adaptive content for a custom learning experience and individualized delivery through AdaptaPASS.</p><span class="read-more">read more</span>
    </div>
    <div class="feature-box">
      <i class="ion-help"></i>
      <h4>Support</h4>
      <p>Direct access to our instructors and CPAs, by phone, email, or via our student-only message board.</p><span class="read-more">read more</span>
    </div>
    <div class="feature-box dark">
      <i class="ion-social-usd-outline"></i>
      <h4>Value</h4>
      <p>Everything you need -- for less. Our course bundle costs hundreds less than competitors.</p>
      <span class="read-more">read more</span>
    </div>
  </div>


</div>

Answer №4

If you do not need to dynamically manipulate the 'boxes', there is a way to achieve it using additional tags and CSS like this:

.feature-container{ box-shadow:0 1px 6px rgba(0,0,0,0.1); position:relative; z-index:9; width:100%; display:inline-block;}
.feature-box{background:#fff; text-align:center; padding:40px 30px; position:relative; width:25%;display:inline-block;}
.feature-box i{font-size:50px; margin-bottom:15px; cursor:pointer;}
.feature-box:hover{background:#208541 !important; color:#f6f6f6;}
.feature-box.dark{background:#f6f6f6;}

.feature-box .mask{display:none;}
.feature-box:hover .mask{background-color:#333;color:white;position:absolute;top:0;right:0;bottom:0;left:0;margin:auto;text-align:center;display:block;}
.feature-box:hover .mask span{position: relative;float: left;top: 50%;left: 50%;transform: translate(-50%, -50%);}
<div class="feature-container" >


<div class="feature-box-container feature-slider">
        <div class="feature-box">
            <i class="ion-ios-list-outline"></i>
                    <h4>Content</h4>
                    <p>Effective learning methodology that focuses on concepts and understanding of AICPA blueprints.</p>
                    <a class="mask" href="#"><span>read more</span></a>
            </div>
            <div class="feature-box dark">
            <i class="ion-ios-cog-outline"></i>
                    <h4>Customization</h4>
                    <p>Adaptive content for a custom learning experience and individualized delivery through AdaptaPASS.</p>
                    <a class="mask" href="#"><span>read more</span></a>
            </div>
            <div class="feature-box">
            <i class="ion-help"></i>
                    <h4>Support</h4>
                    <p>Direct access to our instructors and CPAs, by phone, email, or via our student-only message board.</p>
                    <a class="mask" href="#"><span>read more</span></a>
            </div>
            <div class="feature-box dark">
            <i class="ion-social-usd-outline"></i>
                    <h4>Value</h4>
                    <p>Everything you need -- for less. Our course bundle costs hundreds less than competitors.</p>
                    <a class="mask" href="#"><span>read more</span></a>
            </div>
         </div>


  </div>

if you dont need any fancy styles for the "read more" text, you could use .feature-box:hover::before{} to add the text and center it as I did with .mask span.

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

Issue with Datepicker functionality within the <th> element is causing it to malfunction

Currently, I am attempting to utilize the Bootstrap datepicker, but I am facing an issue when trying to implement it within a table, specifically inside a th element. Below is the structure of my table: <table id="table" class="table table-bord ...

Aligning hyperlinks with background images

Trying to align the link with the background image centered but it keeps ending up at the top, even though I specified the sizes and each background image has different dimensions. HTML <section> <h3>Contact</h3> <ul id ...

Are all elements still displaying the menuBar style? Using the PHP include function, <?php include... ?>

Here is the Menu Bar code I am using: <!DOCTYPE html> <html> <link href = menuBarStyle.css rel = "stylesheet"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <div class = "menu"> ...

Centering items within grid columns for optimal alignment

I have successfully designed a contact form using a CSS grid layout that features 4 input fields and a submit button spanning across 2 columns. Two of the input fields take up 1fr of space each, while the remaining two are 1/3 wide. My challenge lies in c ...

Updating the Background Color of a Selected Checkbox in HTML

I have a straightforward question that I've been struggling to find a simple answer for. Can anyone help me with this? Here's the checkbox code I'm working with: <input type="checkbox"> All I want to do is change the backgr ...

Error: JSON parsing error encountered at position x due to unexpected token

While I understand this question has been asked multiple times before, the situation here is unique. I am utilizing getJSON to retrieve data from a Database. The returned result is a valid JSON (validated by various JSON validators), but I am encountering ...

modal failing to populate values within control elements in modal

Encountering an issue where the code is calling a Modal, but upon loading it fails to populate the controls with values sent into the JavaScript. No errors are thrown, yet all controls remain empty. As a newcomer to AJAX and JavaScript, I suspect there mig ...

Creating a centered arrow using CSS within boxes

Here is the CSS class that I have applied to my divs: .rightarrow{ width: 0; height: 0; border-style: solid; border-width: 10px 0 10px 20px; border-color: transparent transparent transparent #aaaaa9; } This is ...

What is the best way to align a scalable SVG image in the center?

My goal is to horizontally align this SVG within its container, which could be any div, body, or other element. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1250 190" preserveAspectRatio="xMidYMid slice" class="svg-content"> &l ...

Transferring MySQL information to web pages using hyperlinks within a table

We have encountered a challenge while working on our game shop website, specifically related to the purchase link. The link is displayed within a mysql table and currently directs users to the same page. Our goal is to optimize efficiency by adding new gam ...

Guide to presenting pictures from a database using PHP

Currently, my application is able to successfully upload images by saving the file location in a MySQL database. However, I am now facing an issue when trying to display these uploaded images. Below is the code snippet causing problems: include ('co ...

What is preventing this jQuery from altering the opacity?

Currently, I have a piece of code that is intended to change the opacity of a div element from 0 to 1 as soon as the user initiates scrolling on the body. However, it appears to be malfunctioning for reasons unknown. $("bod").load(function(){ document ...

The CSS element is styled with a background color while maintaining a level of transparency

My menu structure is set up as follows: <nav id="main"> <ul id="nav-user"> <li class="user-name"> <span class="name">John Doe</span> <ul class="submenu"> <li>Pro ...

How to send a string as a POST request using jQuery and AJAX

I am working on a custom WordPress plugin and I'm facing an issue with sending a string as POST AJAX parameters. The problem is that the string breaks whenever it encounters '&' in the code snippet below: var data = "http://localhost/wo ...

jQuery functions not functioning properly when triggered by an event

I encountered an issue with my page using jQuery and Bootstrap. Everything was functioning properly until I tried calling a function on an event, which resulted in the console showing an error message saying $(...).function is not a function. For example: ...

Pass information from Vue JS v-for to a button when it is clicked

Just started learning Vue JS and encountered a small issue I'm currently looping through an array with a button inside the div I'm iterating over The goal is to grab the data of the selected item after clicking on the button For example, suppo ...

Unraveling JSON data retrieved from a MySQL query

After successfully encoding a MySQL result from PHP into JSON, I am now faced with the task of decoding it using JavaScript. Let's assume that my string returned is: [{"0":"x","1":"z"},{"0":"xs","1":"zz"}] I would appreciate some guidance on how to ...

Include the data-title attribute within the <td> elements of my datatables

To apply the magic of jQuery datatables to all my tables, I use datatables. For responsive tables, I add data-title to my td's. Is there a way to automatically add data-title to all my td's like below? <td data-title="Fruit">Apple</td&g ...

Synchronization issue between Material UI SelectField component and state is observed in React/Redux setup

My issue involves the LayoutSelector component which contains a drop-down form that updates the state.plate.layout. The state is passed as a prop to the component. On my local machine, the selected menu item accurately reflects the state changes - when a n ...

The success callback function of the jquery.form.js plugin does not execute properly in Internet Explorer

Why is the jquery.form.js plugin fileupload success callback function not working in IE? The fileupload success callback works in Chrome, Firefox, and Safari. I'm puzzled as to why the "SUCCESS callback function" does not work in IE (including IE9, ...