"Enhance your images with dynamic captions using jQuery

Struggling to create an image caption that only appears when hovering over the specific image? Not sure how to select the correct object?

The caption is working, but it's appearing for all images at once. I have attempted to target a single image with no success. Can anyone guide me on selecting the right object?

HTML

<ul id="columns">
        <li class="col-1">
            <div class="photo1">
                    <p>I am doing great. I love this place and I would love to work here.</p>
            </div>
            <div class="photo2">
                <p>I am doing great. I love this place and I would love to work here.</p>
            </div>
            <div class="photo3">
                <p>I am doing great. I love this place and I would love to work here.</p>
            </div>
            <div class="photo4"></div>
            <div class="photo5"></div>  
        </li>
        <li class="col-2">
            <div class="photo6"></div>
            <div class="photo7"></div>
            <div class="photo8"></div>
            <div class="photo9"></div>
            <div class="photo10"></div>
        </li>
        <li class="col-3">
            <div class="photo11"></div>
            <div class="photo12"></div>
            <div class="photo13"></div>
            <div class="photo14"></div>
            <div class="photo15"></div>
        </li>
</ul>

CSS

.photo1 {
        position: relative;         
        background: url(../img/sncc_teaser.jpg) no-repeat;
        width: 250px;
        height: 339px;
        margin-bottom: 5px;
    }
ul li p {
    display: none;
    position: absolute;
    background-color: gray;
    width: 250px;
    color: white;
    margin: 0;
    padding: 0;
    padding-left: 5px;
    bottom: 10px;
    left: 0px;

}

jQuery

$(document).ready(function(){
    $(".col-1").hover
        (
            function($e) 
            {
                $("li p", this).show();
            },

            function($e) 
            {
                $("li p", this).hide();
            }
    );
});

Answer №1

Focus on the DIV, not the whole row:

$(".column-1 div").hover
        (
            function($element) 
            {
                $(this).find('paragraph').show();
            },

            function($element) 
            {
                $(this).find('paragraph').hide();
            }
    );

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

The notification bar only makes an appearance when necessary

I am currently working on a dynamic piece of code that sends a request to PHP and receives a response. The goal is for the notification bar to fadeIn() and fadeOut() every time there is a new notification. However, I have encountered an issue where the n ...

identify when the React component has reached the bottom of the element by reading the

Is there a way to access the scroll handler's event without being able to access offsetTop, scrollTop, etc? class App extends React.Component { handleScroll = e => { console.log(e.target.scrollTop); }; componentDidMo ...

Button on aspx page not functioning properly when clicked

I seem to be experiencing an issue with buttons. To check if the function is being triggered, I used alert("") and found that it does enter the function when the button is clicked. However, after the alert, any other code inside the function seems to not w ...

Is there a way to determine if a button was clicked using twig?

I need assistance with implementing a button in my twig file within a table that will remove an element from an array. Ideally, I would like to remove the element based on its index. From the research I have conducted, it seems that data manipulation shou ...

What is the best method to choose a random color for the background when a button is pressed?

Does anyone know how to create a button that changes the background color of a webpage each time it is clicked? I've been having trouble with the javascript function in my code. I've tried multiple solutions but nothing seems to work. Could someo ...

Utilizing jquery.validate.min.js for efficient form validation

Here is my JavaScript validate function: $("form[id='form']").validate({ Name: "required", submitHandler: function() { formSubmit(); } }); Not only do I wa ...

"Composing perfect sentences: The art of incorporating quotes

I am attempting to include text with quotes in a DIV, like so: "All is well that ends well" The text is generated dynamically and I'm using a JavaScript font replacement plugin (CUFON) to add quotes around the text. Sometimes, the ending quote drops ...

Tips for adding an svg element to an existing svg using d3.js

Can another SVG be appended to an existing SVG parent using d3.js? I have tried using the 'svg:image' attribute, but unfortunately, I lose full control over the inner SVG child. The DOM node is created by d3, but it is not rendered, resulting i ...

The functionality of jQuery.hover with AJAX is malfunctioning

I am facing an issue with my jquery hover combined with $.post method. My initial intention was to create a series of select buttons where hovering would trigger a change in the image being displayed (the image path would be loaded via $.post). The image ...

``In JavaScript, the ternary conditional operator is a useful

I am looking to implement the following logic using a JavaScript ternary operation. Do you think it's feasible? condition1 ? console.log("condition1 pass") : condition2 ? console.log("condition2 pass") : console.log("It is different"); ...

Send an identifier to the following page upon selecting a hyperlink in AngularJS

I am currently working on a project that involves displaying a list of places and allowing users to click on a place to view more details on another page. I would like some guidance on how to implement this feature. Here is the HTML code for Page1: <l ...

Loading dynamic fonts in React MaterialUI

In our web application, each user experiences a unique style with colors, fonts, border widths, and more based on the Material UI JSON theme retrieved from the database upon loading the app. The challenge lies in handling dynamic fonts. What approaches ha ...

An element generated using a JavaScript loop is covering another element in the layout

I am facing an issue with positioning images within a div to a span. The problem arises as the images are overlapping each other and I am uncertain about how to properly place each image when it is added. Below is the code snippet: The CSS: <style ty ...

Tips on altering hover effects?

I am having trouble changing the font size and color of the a when hovering over p. I have been trying to figure this out for a while now, but I can't seem to get it to work. If anyone has any simple links related to this topic, I would greatly appre ...

Utilizing Vue.js to incorporate the isActive property to the class name within a v-for loop, along with implementing dynamic class names

I am currently using a loop to iterate through some data in my store.js file, and everything is functioning as expected. However, I would like to add a condition to check if the Vue instance is active before applying a specific class to the polygon element ...

What steps can be taken to create a two-column layout using the provided HTML code?

I'm having trouble getting my CSS to work properly in IE 8. Any suggestions on how to fix this? Here's the simplified HTML code I'm using: <div id="column-content"> <div id="content"> <p>This is some text</ ...

Flexbox Resizing Notification(?)

Recently, I've been utilizing flexbox in my layout design and it has been a game-changer. However, I am facing an issue that might be linked to my heavy use of AngularJS, particularly the ng-include feature. The specific problem arises when I incorpo ...

How to Build a Number Spinner Using Angular Material?

Is there a number spinner in Angular Material? I attempted to use the code provided in this question's demo: <mat-form-field> <input type="number" class="form-control" matInput name="valu ...

Accessing Microsoft SQL Server Data in Cordova Application utilizing PHP

While I have experience creating simple mobile apps in Cordova, I am now looking to delve into the world of creating database apps. A database app for me means integrating MSSQL Server, HTML, and PHP. In my quest for information on this topic, I scoured v ...

Restrict the maximum character count within a TextArea using jQuery

Is there a way to calculate the total number of characters entered in a text area box? For example, if I have a textbox like this: <%: Html.TextArea("Message", "", new { @title = "Enter the Message" })%> I need to limit the input to 160 characters ...