Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1054681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:26:38+00:00 2026-05-16T17:26:38+00:00

I have 2 spans. First one: <span class=body> Second one: <span class=desc> My CSS:

  • 0

I have 2 spans.

First one: <span class="body">
Second one: <span class="desc">

My CSS:

.desc {display: none;}

What I want to do, is show the second span, when hovering the first. No fancy effects or anything, just show the span.
I know there is a simple jQuery solution out there, but I’m new to jQuery so I’d appreciate some help finding it. 😉

This is what I have so far. Is the syntax correct?

<script>
$(document).ready(function() {
    $(".body").hover(function () {
        $(".desc").toggle();
    })
})
</script>

UPDATE!

As @thenduks pointed out, this results in every .desc element to show when a .body is hovered. As you can probably imagine, I have several .body and .desc and I only want the corresponding .desc to show on hovering the .body.

This is part of my markup: (the whole site is still just local, so I can’t give you an url to test – sorry)

<ul class="form">
    <li>
      <label class="grid_3 alpha caption" for="from_name">Navn/Firma</label>
      <span class="grid_4 body"><input type="text" id="from_name" name="form[from_name]" size="20" value=""></span>
      <span class="grid_5 omega validation"><span class="formNoError" id="component74">Udfyld navn eller firma for afhentningsadressen.</span></span>
      <span class="grid_5 omega desc" style="display: none;"><p>Navnet på afsenderen.</p></span>
    </li>
    <li>
      <label class="grid_3 alpha caption" for="from_address1">Adresse</label>
      <span class="grid_4 body"><input type="text" id="from_address1" name="form[from_address1]" size="20" value=""></span>
      <span class="grid_5 omega validation"><span class="formNoError" id="component75">Udfyld afhentningsadressen.</span></span>
      <span class="grid_5 omega desc" style="display: none;"><p>Adressen på afsenderen.</p></span>
    </li>
    <li>
      <label class="grid_3 alpha caption" for="from_address2">Adresse 2</label>
      <span class="grid_4 body"><input type="text" placeholder="etage/lejlighedsnr./e.l." id="from_address2" name="form[from_address2]" size="20" value=""></span>
      <span class="grid_5 omega validation"><span class="formNoError" id="component76">Invalid Input</span></span>
      <span class="grid_5 omega desc" style="display: none;"><p></p></span>
    </li>
</ul>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:26:39+00:00Added an answer on May 16, 2026 at 5:26 pm

    This will result in hovering over any .body element showing all .desc elements.

    If you post your actual markup we can figure out the proper code to show a corresponding .desc for a hovered .body.

    Update: So, given the markup in the updated answer I’d probably re-write the handler like so:

    $('.body').hover( function() {
      $(this).siblings('.desc').toggle();
    } );
    

    Update2: To have the same behavior on click and active is a bit tricky because as soon as you mouseout of the .body the .desc will hide even if you clicked on it. Doable though… I’d try this:

    var showFunc = function() { $(this).attr('rel', 'open').siblings('.desc').show(); };
    $('.body')
      .click( showFunc )
      .focus( showFunc )
      .hover(
        function() {
          // don't update 'rel' attribute
          $(this).siblings('.desc').show();
        },
        function() {
          // here's the tricky part, if the rel attr is set
          // then dont hide, otherwise, go ahead
          if( $(this).attr('rel') == 'open' ) {
            $(this).siblings('.desc').hide();
          }
        }
      );
    

    So this will make it so that just hovering hides/shows as before, but if you click it will ‘stick’ open. In this case you’d probably want the show handler to also hide other open .descs so that you wont end up tons of open ones all over. So maybe showFunc should be:

    var showFunc = function() {
      $("." + $(this).className).attr('rel', '');
      $(this).attr('rel', 'open').siblings('.desc').show();
    };
    

    … which will simply clear all other rel attributes on previously clicked/focused elements. I’m sure this would still need tweaking, but hopefully it points you in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two functions. One checks for a class and if none
I have a div which contains 2 elements. First element is a span and
I have a div in which I have spans and I want to read
I have a time interval that spans years and I want all the time
I have the following code, basically it is performing two operations. First one being
I have a list that has 5 items in, the first one (on load)
I have the following DOM structure: /*:DOC += <div id='testDiv' class='testDivClass'><div id='innerTestDiv'></div></div><span id='testSpan' class='testSpanClass'><span
i want to have divs in one div and they need to be in
Im trying to select the span by using the (.class) selector but for one
So I have several DIVs called achievement, and each one contains a span called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.