Only reveal a single div when hovering

I am currently working on a project that involves utilizing the Wikipedia API to allow users to search for and retrieve information from Wikipedia. I have made significant progress, but I have encountered an issue. When hovering over the "each-list" div, the "show-more" div appears from the right side of its parent div, which is the "each-list" div. Subsequently, when hovering over the "show-more" div, another div called "titleDesc" is displayed. The problem lies in the fact that all "titleDesc" divs appear when hovering over the "show-more" div, whereas I only want the related div to be displayed.

Here is the JavaScript code I am using:


var apiKey = "*****";
var appendApiKeyHeader = function(xhr) {
  xhr.setRequestHeader('Api-Key', apiKey)
};

var name = "Eminem";
var searchRequest = {
  "phrase": name
}

$('#search').click(function() {

  var foundArticle = $("#query").val();

  console.log(foundArticle);

  var wikiUrl = 'http://en.wikipedia.org/w/api.php?action=opensearch&search=' + foundArticle + '&format=json&callback=wikiCalback';

  // Clear content before AJAX call
  $(".list-container").html("");

  $.ajax({
      url: wikiUrl,
      dataType: "jsonp",
      success: function(response) {
          var artList = response[1];
          console.log(artList);
          for (var i = 0; i < artList.length; i++) {
            var title = artList[i];
            console.log("Number" + " " + i + " " + title);
            var titleDesc = response[2][i];
            console.log("Number" + " " + i + " " + titleDesc);
            var url = 'http://en.wikipedia.org/wiki/' + title;

            $(".list-container").append(
              '<span class = "each-list">' +
              '<a href="' + url + '" target="_blank" >' +
              title +
              '</a>' +
              '<div class="show-more">' +

              '<div id="show-more-inner">MORE</div>' +

              '</div>' +

              '</span>' +

              '<div class="titleDesc">' + '<p>' + titleDesc + '</p>' + '</div>'

            );

          }

          $('.show-more').hover(

            function() {
              $('.titleDesc').hide();
              $(this).parent().find('.titleDesc').show();
            }

          );
        }

    })

  return false;

});

function GetSearchResults() {
  $.ajax({
    type: "GET",
    beforeSend: appendApiKeyHeader,
    url: "https://api.gettyimages.com/v3/search/images",
    data: searchRequest
  }).success(function(data, textStatus, jqXHR) {
    var uri = data.images[0].display_sizes[0].uri;
    $(".images").append('<img src = "' + uri + '" />');
    console.log(data);

  }).fail(function(data, err) {

    console.log(data);

  });
}

GetSearchResults();

This section of code controls the display of the "titleDesc" div:


$('.show-more').hover(

    function() {
      $('.titleDesc').hide();
      $(this).parent().find('.titleDesc').show();
    }

  );

By making this adjustment, only the relevant div should be displayed when hovering over the "show-more" div.

If you would like more information about the project, please feel free to review it. https://i.sstatic.net/ple1r.png

Answer №1

When the ".show_more" element triggers the "hover" event, $(this) is selected.
  It then looks for the parent element with a class of ".each-list".
  Next, it targets the sibling element with a class of "titleDesc" and displays it.

Please note that the generated markup is invalid as the <span> element should only contain inline elements and not block elements like <div>.

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

Strange HTML antics

On my website, I encountered an issue when trying to register without entering any information into the required fields. The errors were correctly displayed in this screenshot: https://i.sstatic.net/wrxjt.png However, after inserting random characters in ...

Ensure that the heights of columns in UL CSS are aligned regardless of the number of lines they contain

In my current project, I am using CSS columns to establish a two-column layout for an unordered list. Here is the code snippet: HTML <div class="meta-data"> <ul> <li><i class="fa fa-chevron-right fa-xs"></i><str ...

"Update the Database in Real Time with Second Entries Without the Need to Refresh

I've encountered an issue with my code that only allows data to be inserted into the database the first time. After trying to insert a second time, I have to refresh the page. Can someone please assist me? Below is a form where users can enter inform ...

What is the reason behind the reversal of the response list by $.getJSON?

Here is the code I am working with: // Setting up an array for tooltip content var Data = []; var search = $("input#field_search").val(); var combo = $("select#search_option").val(); var jsonUrl = "ajax.php?module=formation&action=get_participant_list ...

Setting a checkbox to true within the MUI Data Grid using my input onChange event - how can I achieve this?

I am looking to highlight the selected row in my usage input onChange event. https://i.stack.imgur.com/rp9rW.png Details of Columns: const columns = [ { field: 'part_code', headerName: 'Part Code', width: 200 }, { ...

Using jQuery to send information to PHP via an AJAX request

When attempting to use jQuery to send form data to a PHP file, nothing happens when the button is pressed. The jQuery code snippet: $(document).ready(function(){ $("#daily_user_but").click(function(){ $('#result').html('<im ...

Arranging the 1st element of the 1st row to be placed at the end using CSS Flex

One of my challenges involves choosing between two options: https://i.sstatic.net/JpWiGfW2.png In my project, I am utilizing a container with flex-wrap: wrap to showcase items of equal dimensions. However, the first item in this container stands out due t ...

revealing the hidden message on the back of the card

I have been working on creating flipping cards for my website using CSS, but I am facing an issue. Even after styling my cards as per the provided CSS code, I am unable to make them flip when I hover my mouse over them. .row { padding-top: 25px; } .c ...

The form submission feature is malfunctioning due to JavaScript issues

I have forms that allow file uploads (images), and I am trying to restrict the size of those images to 500KB. However, for some reason, the forms are not submitting and I am unsure why. Below is the jQuery code: $('form').on('submit', ...

Shifting a division using insertAfter

Hey there! I'm having a bit of trouble using the insertAfter function. In each product in my store, I need to position an "add to cart" button after the price. This is the code I tried: <Script type="text/javascript" > jQuery(document).read ...

ExpressJs does not support query parameters with the router.get method

I am currently working on developing an Express app. Here is the code snippet I am using: const express = require("express"); const router = express.Router(); router.get("/:id", ControllerHandler(UserController.getSingle, GetUserReque ...

Exploring Request Parameters in SailsJS

I am facing an issue with logging requests in my Sails app. While I have managed to log the requests successfully, I am unable to log the parameters of the request. myRequestLogger: function(req, res, next) { if (sails.config.environment === & ...

Numerous anchor links are present

Is it possible to eliminate the red lines between "google links" while keeping the border color as red? How can I achieve this? Here is the code snippet provided: <!doctype html> <html> <head> <title>Website</title> </he ...

Error message: The attempted import failed because ' is not exported from the module

I am facing an issue with resolving my problem. In a file named lama.d.ts, I have declared a class using the following code: export declare class lama { // code here } After that, I tried to import this class in another file within the same folder ...

What is the best way to make a div span the entire height of the body?

I have a menu that I want to wrap inside a yellow div. The yellow div should take up the entire height of the green square, regardless of the content size in the green square. For example, if the orange square expands, the yellow div should also expand. h ...

jQuery does not change the scroll position of elements

I'm looking to implement a feature on my website where certain points act as "magnets" and when the user is near one of these points, the window automatically scrolls to the top. I found a jQuery plugin that does something similar which you can check ...

SortTable - Refresh Dropdown Filter in Header After Adding Row to Table

My tablesorter table initially displays two entries in the "License" Filter. https://i.sstatic.net/4XODb.png If I dynamically add a row, the table now looks like this: https://i.sstatic.net/vMMYc.png I have attempted to update the table using the follow ...

Databinding with AngularJS inside pre tags

Attempting to demonstrate databinding in a code snippet, but it keeps evaluating within the pre tag! Even when using { and }, it still evaluates. It's almost comical how such a simple issue is proving difficult to find an answer for online. ...

Compiling modal window content in AngularJS can lead to the creation of controllers that are left disconnected

I implemented a modal window triggered by fancybox in my project. Once the modal is displayed, fancybox triggers a "modalShown" event that is listened for by AppController. In this listener, $compile is called on the modal content to create the ModalContro ...

ReactiveJS - Adding elements to an array and encountering the error of undefined

In two separate JavaScript files, I have 2 arrays declared as shown below: Index.JS: const [product, setProduct] = useState([]); const [item] = useState([ { name: 'Blue Dress', Image: '/static/media/Dress.1c414114.png', Pr ...