Replace the text in a different Div

Hello everyone, I'm struggling with an issue in my coding.

Here is the HTML:

<a href="aboutme.php">
    <div class='aboutus'>
        <div id="mbubble">
            stuff inside here
        </div>
    </div>
</a>
<div id='title'>
    <div class="thome"><p style="letter-spacing:10;">Text BEFORE</p></div>
    <div class="tabout"><p style="letter-spacing:10;">Text AFTER</p></div>

I am trying to make it so that when I hover over the "mbubble" div, the text of the "thome" class changes. I have attempted to do this by toggling visibility but it doesn't seem to be working.

This is the CSS I have used:

#mbubble:hover ~ .thome { visibility:hidden; }
#mbubble:hover ~ .tabout { visibility:visible; }

Unfortunately, it's not having any effect. Can anyone suggest a different method or provide guidance on how to achieve this effect?

Thank you in advance, Michael

Answer №1

What if we try this instead:

$('#mbubble').mouseover(function () {   
    $('.thome').html('<p style="letter-spacing:10;">THINGS HAVE CHANGED</p>');
})

Answer №2

If the structure you're working with is as straightforward as you say, here's a clever solution involving pointer-events:

The concept is to disable pointer-events on 'a' and only enable it on #mbubble. This way, when you hover over a child element, the parent element won't be affected unless targeted specifically.

a {pointer-events:none; }
#mbubble {pointer-events:auto;}
a:hover + #title .thome , .tabout {display:none;}
a:hover + #title .tabout {display:block;}
<a href="aboutme.php">
       <div class='aboutus'>i don't trigger anything
            <div id="mbubble">
                I DO
            </div>
        </div>
   </a>
   <div id='title'>
        <div class="thome"><p style="letter-spacing:10;">Text BEFORE</p></div>
        <div class="tabout"><p style="letter-spacing:10;">Text AFTER</p></div>

If you find that using pointer-events along with a:hover works for your purposes, keep in mind that it's most useful when there are other elements inside <a> that shouldn't trigger the link. In this case, clicking on #mbubble will activate the link. Was the example provided too simplistic? If not, simply employ a:hover instead.

http://caniuse.com/#search=pointer-events

Answer №3

Creating this effect in CSS is possible, but not recommended. However, you can achieve a quick inline solution using JavaScript and the DOM traversal method:

It's important to note that this approach may lead to unexpected behaviors and makes it difficult for users to copy content by right-clicking. Therefore, directly using inline JavaScript is not advisable. There are workarounds available to address this issue. Good luck!

  <a href="aboutme.php">
       <div class='aboutus'>
            <div onmouseover="document.getElementById('title').children[0].children[0].textContent='Enter the void!'" id="mbubble">
                stuff inside here
            </div>
        </div>
   </a>
   <div id='title'>
        <div class="thome"><p style="letter-spacing:10;">Text BEFORE</p></div>
        <div class="tabout"><p style="letter-spacing:10;">Text AFTER</p></div>

A better approach would be to use a function like this:

  <a href="aboutme.php">
       <div class='aboutus'>
            <div onmouseover="changeText()" id="mbubble">
                stuff inside here
            </div>
        </div>
   </a>
   <div id='title'>
        <div class="thome"><p style="letter-spacing:10;">Text BEFORE</p></div>
        <div class="tabout"><p style="letter-spacing:10;">Text AFTER</p></div>

        <script>
        function changeText() {
          document.getElementById('title').children[0].children[0].textContent='Enter the void!'
        }
        </script>

For a cleaner solution, consider adding an event listener in JavaScript, like so:

- <div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>       <a href="aboutme.php">
           <div class='aboutus'>
               <div id="mbubble">
                   stuff inside here
               </div>
           </div>
       </a>
       <div id='title'>
           <div class="thome">
               <p style="letter-spacing:10;">Text BEFORE</p>
           </div>
           <div class="tabout">
               <p style="letter-spacing:10;">Text AFTER</p>
           </div>
          <script>
           var toBeWatched = document.getElementById('mbubble');
           toBeWatched.addEventListener("mouseover", function(event) {document.getElementById('title').children[0].children[0].textContent
   = 'Enter the void!';setTimeout(function() {  document.getElementById('title').children[0].children[0].textContent 
   = 'Text BEFORE!!!';
               }, 2500);
           }, false);
         </script> 

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

Extracting values from a JSON object in JavaScript

Is there a way to retrieve the _id and state values from the provided data? Check out the data { "data": { "totalSamplesTested": "578841", "totalConfirmedCases": 61307, "totalActiveC ...

Component with Next.JS Server-Side Rendering

Is it possible to integrate a module into my project that only supports server side rendering? Here is the current project structure: index.js view.js part.js (Class component) Currently, I am able to use the module in the getServerSideProps method in ...

Instructions on utilizing the signUp() function in Supabase for including extra user details during the registration process

My latest project involves building a Vue.js application with authentication using Supabase. I've been trying to implement the signUp() method from Supabase in order to collect extra user data during the sign-up process. In my code, I added a property ...

What is the best way to align a button with a title on the right side of a page?

Is it possible to align my button to the top right, at the same height as the title in my design? Here is an example: view image here This is what I have achieved so far: view image here I suspect there may be an issue with my divs. The button doesn&a ...

Ant Design: How can a SubMenu be turned into a clickable link?

Currently, I am developing a Next.js application and utilizing antd's Menu and Submenu components for my NavBar. My goal is to make the SubMenu items clickable links. How can I achieve this functionality? <Menu className={styles.menuContainer} mode ...

The PrimeNG checkbox is not reflecting the updated ngModel changes in the view

I'm dealing with a list of PrimeNG checkboxes that are connected to an array named selectedItems through the ngModel directive. Initially, I have some items already checked in this array. The tricky part is that I need to add items to the selectedItem ...

"The combination of Node.js, Express, and Angular is causing a continuous loop in the controller when a route is

Currently, I am utilizing node js alongside Express. Angular js files are being loaded through index.html. The code for app.js is as follows: app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); ...

What is the best way to access a ViewChild element in the parent component without rendering it?

I am currently utilizing a component within another component in the following manner: <inline-help> <help-title>{{::'lang.whatIsThis'|i18n}}</help-title> <help-body i18n="lang.helpBody">& ...

I am experiencing issues with launching chromium while running Puppeteer on Windows 11 using node js v19.4

Upon following the installation instructions in the documentation to install puppeteer with npm install puppeteer, I attempted to run the example for downloading a webpage as a PDF. However, every time I try to execute the code, Node.js returns the followi ...

Issue with Chrome's webkit causing images to display incorrectly in slideshow

After researching the issue with webkit browsers and images, I came across a problem that I haven't been able to find a solution for yet. I developed a slideshow using jQuery that arranges images in a row and uses a mask element (with overflow: hidde ...

Error: Attempting to access property 'baseHref' of an undefined value is not possible

Creating a webpack configuration for Angular 7 has been my recent project. I found a helpful tutorial on how to customize build configuration at this link. I decided to use the @angular-builders package for this task. Upon checking my index.html file, I m ...

Storing a byte array in a local file using JavaScript: A Step-by-Step Guide

Recently, I encountered an issue while working with an openssl certificate. Specifically, when I tried to download the certificate from my API, it returned byte arrays that I needed to convert to a PEM file in order to access them through another API. The ...

Allowing unauthorized cross-origin requests to reach the SailsJS controller despite implementing CORS restrictions

My cors.js file has the following configuration: module.exports.cors = { allRoutes: true, origin: require('./local.js').hosts, // which is 'http://localhost' } I decided to test it by making a request from a random site, Here is ...

Retrieving a MAC address from a device using a web script or HTTP protocol

Is it feasible, with access to all end user devices, to request the device's MAC address using web scripting in Apache/IIS/Nginx? Would PHP, Perl, or ASP be able to accomplish this task? The client devices run on iOS, so the method described here wil ...

Is there a way to accomplish this without using settimeout?

Whenever the Like button is pressed, I want to trigger the loading process I expect to see LOAD_POST_SUCCESS immediately after LIKE_POST_SUCCESS Pressing the Like button should initiate the load process After LIKE_POST_SUCESS, I want to see LOAD_POST_SU ...

Tips for displaying "onclick" content beside dynamically generated content

I am working on a feature where a dynamically generated list has radio buttons displayed next to it. The goal is to show a dropdown list next to the specific radio button and list item that was changed. Essentially, if the radio button is set to "yes," I w ...

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 ...

In search of a jQuery parser for HTML strings that can accurately parse <a> links and <img> images

Is there a HTML string jQuery parser available, specifically for parsing <a> links and <img> images? Alternatively, I am looking for code that can extract all links and images from a HTML string, which can potentially be very large. For exampl ...

Permit the use of the "&" character in mailto href links

When including an email mailto href link and using a & character in the subject, it can cause issues with code rendering. For example, if the subject is "Oil & Gas," only "Oil" may show up. In most cases, you could simply replace the & with th ...

Encountered an issue while compiling code using the Istanbul plugin

I'm currently working on generating a code coverage report for my ReactJS project using the babel-istanbul-plugin. However, when I incorporate "istanbul" as a plugin in my .babelrc file and attempt to build, I encounter the following error: ERROR in ...