Javascript problem: Understanding the .children method and how to use it

I have implemented a basic JavaScript/CSS code to show a tooltip/enlarged photo feature.

You can visit the actual page here. The thumbnail images are located on the right-hand side.

The issue I am facing is that when using the mouseenter function, the tooltip doesn't display the correct image. It was working fine initially, but after some CSS changes, it started pulling the wrong image. How can I ensure that the correct image is shown in the tooltip, which is defined in the class tooltip? Thank you.

<script type="text/javascript">
// This script loads once the document is fully loaded
$(document).ready(function () {
    // Get all the thumbnail elements
    $('div.thumbnail-item').mouseenter(function(e) {

        // Calculate the position of the image tooltip
        x = e.pageX - $(this).offset().left;
        y = e.pageY - $(this).offset().top;

        // Set the z-index of the current item and display the image tooltip
        $(this).css('z-index','15')
        .children("div.tooltip")
        .css({'top': y + 10,'left': x + 20,'display':'block'});

    }).mousemove(function(e) {

        // Calculate the position of the image tooltip          
        x = e.pageX - $(this).offset().left;
        y = e.pageY - $(this).offset().top;

        // Make the tooltip follow the mouse pointer
        $(this).children("div.tooltip").css({'top': y + 10,'left': x + 20});

    }).mouseleave(function() {

        // Reset the z-index and hide the image tooltip 
        $(this).css('z-index','1')
        .children("div.tooltip")
        .animate({"opacity": "hide"}, "fast");
    });
});
</script>
<style>

.thumbnail-item { 
position: relative; 
float: left;  
margin: 0px 5px; 
}

.thumbnail-item a { 
display: block; 
}

.thumbnail-item img.thumbnail {
border:3px solid #ccc;  
}

.tooltip { 
display: none; 
position: absolute; 
padding: 8px 0 0 8px; 
}

.tooltip span.overlay { 
background: url(<?php echo base_url(); ?>3_party/imgtooltip/images/overlay.png)     no-repeat; 
position: absolute; 
top: 0px; 
left: 0px; 
display: block; 
width: 350px; 
height: 200px; 
 }
</style>
<div class="picture"><?php echo '<img class="main_picture_box" src="' . base_url() . 'uploads/big_' . $main_image->image . '">'; ?></div>

<div class="thumb-contain">
<!--picture loop max 25-->
<?php
foreach ($images as $i) {
    echo '<div class="thumbnail-item">';
        echo '<a href="#">';
            echo '<img class="test" id="big_pic" onclick="swap()" src="' . base_url() . 'uploads/small_' . $i->image . '" class="thumbnail"/>';
        echo '</a>';
        echo '<div class="tooltip">';
            echo '<img src="' . base_url() . 'uploads/' . $i->image . '" alt="" width="330" height="185" />';
            echo '<span class="overlay"></span>';
        echo '</div>';
    echo '</div>';
}
?>

Answer №1

If you take a look at listings_layout.css near line 167, you will find the following:

#tbroker-content .contain .thumb-contain .thumbnail-item img{
  width:52px;
  height:52px;
  margin:2px;
}

This code targets all images under .thumbnail-items. To specifically target only images that are children of an anchor tag, you can modify it like this:

#tbroker-content .contain .thumb-contain .thumbnail-item a img{
  width:52px;
  height:52px;
  margin:2px;
}

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

Managing numerous requests simultaneously without causing one to delay or block the others

I am facing challenges when it comes to managing multiple client requests. Ideally, each route should be handled asynchronously, but I am struggling to handle one request after another without the previous one interfering with the next one. In the code sni ...

Utilizing nested styling with material-ui v1's withStyles feature

Currently, I am working on building a React component using separate major containers as React class components. While I understand how to use withStyles with a single component, I am a bit confused when it comes to applying styles to more than two compone ...

Should I retain a duplicate of the js library in the lib or vendor directory even if it has already been installed using npm?

Query 1 : As I install my project dependency libraries using npm, they are saved in the npm_modules folder. I wonder if it's necessary to also duplicate the library files like angular.js, angular-route.js in a separate lib or vendor folder for permane ...

Is optgroup malfunctioning in IE 10?

My main question is: does optgroup not function properly in IE? The Plnkr code works fine in Chrome but encounters issues in IE 10. I'm trying to find a solution that will work across both browsers. Is this a known problem? In Chrome, I can expand/co ...

Leveraging Firebase and Cloud Functions to dynamically update values based on date conditions

In my database, I have a collection of consultations with the value 'date' in TimeStamp format (e.g. October 31, 2020 at 1:00:00 AM UTC+1) and another value called "status" which is either true or false. Each TimeStamp always has the same time - ...

The delete functionality seems to be malfunctioning within Postman

const express = require("express") const app = express() app.use(express.json()) const usersList = [{id :1,name:"naser",age:26},{id :2,name:"mosa",age:46}]; app.post('/users',(req,res)=>{ const newUser = re ...

What is the best way to merge 60 related jquery functions into a unified function?

I designed a webpage that serves as an extensive checklist. When you click on the edit button for a checklist item, a modal window opens up. This modal window contains a radio button to indicate whether any issues were found during the check. If "Yes" is s ...

Transforming a callback function into a Promise: A step-by-step guide

I'm currently utilizing Bluebird promises and attempting to make the following function work with Promisify: var jwt = require('jsonwebtoken'); function _test_encode() { var cert = fs.readFileSync('public.pub'); return j ...

How come (23 == true) is incorrect but (!!23 == true) is correct? After all, there is === for exact comparisons

The question boils down to this: are both 23 and true truthy values? If so, shouldn't they be equal under the loose comparison operator ==? However, there is also the strict comparison operator === for cases where precise equality is required. UPDATE ...

Determine whether there is greater available space above or below a specific element within the DOM

I'm looking to create a dynamic layout where an input field is accompanied by a list in a div, positioned either above or below depending on available space. This setup needs to account for the fact that the input field could be located anywhere on th ...

You are unable to select the radio buttons or checkboxes while they are located within the BootStrap

I am facing an issue with my bootstrap modal that includes radio buttons and checkboxes. When I place the code for these elements outside the modal, they work perfectly. However, once I move them inside the modal, I am unable to check or select them. I am ...

Is it possible to remove or delete a module in AngularJS?

Is there a way to clear the memory of a previous module in my app that I won't be using after routing to a different location? For instance, let's say my main Angular module is "WebApp" which has dependencies on modules like "catalogApp", "Payme ...

Display nested array objects of varying levels within VUE

How do I display nested elements on the UI when dynamically generated based on a parent element's selected option (e.g. List)? For example, in the code below, when creating a field and selecting the List option, another nested should appear, and so o ...

Is there a way to apply styles to a checkbox's child element depending on the checkbox's state without relying on ternary operators within Styled Components?

I am currently working on styling this component using Styled Components, but I feel like my current approach is a bit of a hack. What would be the best practice for incorporating Styled Components to style this component effectively? If I were to use Pla ...

Is JSF h:outputStylesheet converter the solution for creating dynamic CSS?

Recently, I came across the <h:outputStylesheet/> tag with a converter attribute. I tried attaching a dummy (pass-through) converter to it, but to my surprise, nothing happened. Upon further investigation, it appears that the converter is not even in ...

Access an HTML file in Text Edit on a Mac directly from a web browser

Is there a way to utilize Javascript or another appropriate script to open an HTML file in Text Edit on my Mac? I have created a local web page using Text Edit that has different tabs linking to other Text Edit files within the page. I am looking for a m ...

activating the submit button depending on the user input

My goal is to create a form with a textarea and a submit button that can be enabled or disabled based on whether there is any input in the textarea. I have confirmed that both the submit button and content are being selected correctly (I'll provide a ...

jQuery floating sidebar that dynamically adjusts position based on content overflow

I've come across an interesting scenario with a fiddle that I'm working on: http://jsfiddle.net/yFjtt/1/ The main concept is to allow users to scroll past the header and have the sidebar 'stick' in place as they continue scrolling down ...

Creating a PHP JSON response that incorporates an HTML layout is a dynamic

I'm having some trouble with a certain issue: I am attempting to develop a jQuery/AJAX/PHP live search bar. Although I am successfully calling search.php, the response displayed in the console always includes the contents of my master.php file (which ...

Utilize the HTTP.get function to serve files in the img src attribute

I am facing an issue where my file can only be accessed if I include an x-authentication token in the header of the "GET" http request. Unfortunately, using a cookie is not an option in this case. This means I cannot simply call for the file by its URL in ...