Replace the single text area with multiple div elements and update the image within each div

Within the 'Pinctitle' area, there is text that I want to change each time a Pselectorbutton is hovered over with a fading effect. Additionally, I would like the image inside the 'Pselectorbutton' to change at the same time.

Currently, I have the image set as a background image. I was considering using hover to achieve this effect, but I am aware that the related div must be used, so I may need to incorporate some JQuery into my page.

Is it possible to accomplish this entirely using CSS?

 .Pselectorinside {
    position: relative;
    }
    
    .Pincludes {
    font-size: 12px;
    }
    
    .Pinctitle {
    font-size: 21px;
    }
    
    .Pselectorrow {
    width: 100%;
    margin-left: -21px;
    }
    
    .Pselectorbutton {
    float: left;
    width: 30px;
    height: 30px;
    margin-left: 21px;
    background-color: blue;
    }
    
    .Pselectorbutton .one{
    background-image: url(../images/oneA.jpg)
    }
    
    .Pselectorbutton .one:hover{
    background-image: url(../images/oneB.jpg)
    }
    
    .Pselectorbutton .two{
    background-image: url(../images/twoA.jpg)
    }
    
    .Pselectorbutton .two:hover{
    background-image: url(../images/twoB.jpg)
    }
    
    .Pselectorbutton .three{
    background-image: url(../images/threeA.jpg)
    }
    
    .Pselectorbutton .three{
    background-image: url(../images/threeB.jpg)
    }
    <div class="Pselectorinside">
        <div class="Pincludes">PROJECT INCLUDES
        </div>
        <div class="Pinctitle">Photography
        </div>
        <div class="Pselectorrow">
            <div class="Pselectorbutton one">
            </div>
            <div class="Pselectorbutton two">
            </div>
            <div class="Pselectorbutton three">
            </div>
        </div>
    </div>

Answer №1

If you're in need of something similar, check out this link: jsFiddle

let currentTitle = $('.TitleClass').text();

$('body').on('mouseenter', '.ButtonClass', function(){
    let newText = $(this).data('title');
    $('.TitleClass').text(newText);
});

$('body').on('mouseleave', '.ButtonClass', function(){
    $('.TitleClass').text(currentTitle);
});

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

Bootstrap3 and jQuery are attempting to achieve vertical alignment

I am trying to vertically align Bootstrap col-md* columns. I have two blocks, one with text and one with an image, and I want them to be equal in height with the text block vertically centered. My current solution is not working correctly. Can someone plea ...

What is the best way to apply a 2px padding to text-decoration: underline?

As a dedicated frontend developer, I believe in creating underlines with a 2px padding instead of the default 1px. Is there an easy solution for achieving this? PS: Yes, I am aware of using a div with a black background color and 1px * Npx with position: ...

Building a single-page app optimized for mobile viewing with Foundation framework

Currently facing an issue with the scaling of the viewport on certain mobile devices when loading new content via ng-include in our responsive website built on Foundation. The problem arises as the width of the page breaks, leading to horizontal scrolling. ...

Error: Unable to access property XXX because it is not defined

Upon trying to serve my application, I encountered errors in the console similar to the one below. It seems to be related to angular-animate. How can I resolve this issue in angular? Can someone assist me with fixing it? Uncaught TypeError: Cannot read pr ...

What specific @media query should be used to target Windows Phone 8+ with high resolution?

As per the insights shared in Brett Jankord's article on Cross Browser Retina/High Resolution Media Queries The information suggests that Windows 8 phones do not adhere to device-pixel-ratio media queries. Are there alternative methods to target W ...

Adjacent components

I have a query regarding the utilization of Angular. I aim to align the sentences side by side. These are two distinct components that I developed. I wish for recipe-list and recipes-details to function properly, with both statements displayed alongside ...

Exploring the Power of Two jQuery Ajax Functions in Your Script

Is it possible to provide guidance on how I can successfully execute two separate Ajax calls within a single script without encountering conflicts? A sample of the current script structure is as follows: <script type="text/javascript"> $(document).r ...

The JavaScript setTimeout function not triggering repetitively for 10 instances

I'm facing an issue with a JavaScript/jQuery function that is designed to call itself multiple times if there is no available data. This is determined by making a web service call. However, the logging inside the web service indicates that it is only ...

rearranging the positioning of links in the HTML navbar

Is there a way to prevent other links in the navbar from moving up slightly when hovering over one link and creating a line (border bottom)? ` .n24{ margin-top: 2px; padding: 14px 14px; } .n25{ margin-top: 2px; padding: 14px 14px; } . ...

Tips for making a hide and reveal FAQ section

Currently working on creating a FAQ page for my website, I ran into a challenge. My goal is to have a setup where clicking on a question will reveal the answer while hiding any previously open answers. So far, I have managed to achieve this functionality p ...

The background color should only cover a specific percentage of the element

Here is the current structure I have: <li class="myclass" ng-class="myAngularClass"> <div> div1 <div> div2 </div> </div> </li> The li element has dynamic dimensions and width. The class "myAngularClass" i ...

Activate Click, or Pop-up Box

I've been attempting to log in to the Udemy site using JavaScript, but I'm having trouble triggering the click action on the "log in" link. Unfortunately, the .click() method doesn't seem to be working when I try to select the element. The l ...

Text within the div element causes the displacement of other adjacent div elements

When the text in mondaySpecial extends to a second line, it pushes tuesdaySpecial-saturdaySpecial further down on the page, disrupting the layout of the divs. The same issue occurs with other specials as well. Is there a way to prevent this from happening? ...

Trigger a keypress event following the activation of a button

I've been trying to simulate the press of the backspace key on the keyboard after clicking a button, but all my attempts have been unsuccessful. Here is the code I'm using: function rtf(){ document.getElementById("u0u").focus(); $('#u0u ...

Server has sent an Ajax response which needs to be inserted into a div

I have a modal window that sends a POST request to the server. Before returning to the view, I store some information in ViewData. Here's an example of what I'm doing: ViewData["Msg"] = "<div id=\"msgResponse\" class=\"success ...

Guide to setting up a Datetime picker in Bootstrap 5 user interface

I've been struggling to implement a datetime picker for Bootstrap 5 (my front end is using Bootstrap 5.1.0). While I came across a solution for Bootstrap 3, unfortunately it doesn't seem to work with Bootstrap 5. ...

PageCallbacks in .NET 1.1

Is it possible to utilize PageMethods in .NET 1.1 for making server-side method calls from the client side? Could you provide a brief explanation on how to use this feature by calling PageMethods.MyMethod(); ? ...

The @mouse-down event in Vue does not seem to be firing

I'm new to web development and I'm having some issues with Vue. I learned from a tutorial that I can use @click when a button is pressed, and it works fine. Now I want to create a simple mechanism to detect when the mouse is clicked and released ...

Contrasts between space and the greater than selector

Can you explain the distinction between selector 6 and selector 7 as outlined on the w3 website? Inquiring minds want to know. ...

Calling Ajax to Flask for fetching MySQL query results

My goal is to populate a drop-down list in my HTML using AJAX by calling my flask app app.py from app.js. I am attempting to load the data when the page initially loads and triggering the AJAX within $(document).ready as shown below: Here is the content o ...