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 8763065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:41:38+00:00 2026-06-13T15:41:38+00:00

I am using jQuery to show or hide a span. But I want the

  • 0

I am using jQuery to show or hide a span. But I want the <div> to appear in the same place as the link I click. The current code actually shows the <div> tags on the left side of the screen. Here is the code i am using.

<script>
$(document).ready(function(){
    $(".slidingDiv").hide();
    $(".show_hide").show();
    $('.show_hide').click(function(){
    $(".slidingDiv").slideToggle();
      return false;
    });
    $(".slidingDiv1").hide();
    $(".show_hide1").show();
    $('.show_hide1').click(function(){
    $(".slidingDiv1").slideToggle();
      return false;
    });
});
</script>

Span Tag:

<span>
 <a href="#" class="show_hide">Japan</a>
 <span class="slidingDiv">
   <img src="02-1 ImageFiles/01 Japan.JPG" style="width:235px; height:245px;">
   <a href="#" class="show_hide">Close</a>
 </span>
 is made up of islands, regions, prefectures (government districts), cities, and surrounding communities. The main island, Honshu, has thirty-four prefectures making up five regions. The 
 <a class="show_hide1" href="#">Tōhoku Region</a>
 <span class="slidingDiv1">
  <img src="02-1 ImageFiles/02 TohokuRegion.JPG" style="width:217px; height:236px;">
  <a href="#" class="show_hide1">Close</a>
</span>
  • 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-06-13T15:41:40+00:00Added an answer on June 13, 2026 at 3:41 pm

    this can be your HTML part:

    <a href="#" class="show_hide" style="position: relative;">Japan</a>
    <span class="slidingDiv" style="position: absolute; left: 0;">
        <img src="02-1 ImageFiles/01 Japan.JPG" style="width: 235px; height: 245px;" />
        <a href="#" class="show_hide_close">Close</a>
    </span>
    is made up of islands, regions, prefectures (government districts), cities, and surrounding communities. The main island, Honshu, has thirty-four prefectures making up five regions. The
    <a class="show_hide" href="#" style="position: relative;">T&#197;hoku Region</a>
    <span class="slidingDiv" style="position: absolute; left: 0;">
        <img src="02-1 ImageFiles/02 TohokuRegion.JPG" style="width: 217px; height: 236px;" />
        <a href="#" class="show_hide_close">Close</a>
    </span>
    

    and this can be your script part:

    <script type="text/javascript">
        $(document).ready(function () {
        $(".slidingDiv").hide();
        $(".show_hide").show();
    
        $('.show_hide').click(function () {
            var el = $(this);
            var slidingDiv = el.find("span.slidingDiv");
            if (slidingDiv.length > 0) {
                slidingDiv.slideToggle(function () { el.after(slidingDiv); });
            }
            else {
                slidingDiv = el.next("span.slidingDiv");
                el.append(slidingDiv);
                slidingDiv.slideToggle();
            }
            return false;
        });
        $('.show_hide_close').click(function () {
            $(this).parent().parent("a.show_hide").click();
            return false;
        });
    });
    

    Explanation:

    • the script will append the span to the anchor on click and will move it back to its original place on closing.
      the reason is that you cannot wrap a block (here is the span) in an anchor tag in the html code, so we will do it at run-time. and we should wrap it because we need to show the span below the anchor tag.

    • span containing the img and close button should have absolute position

    • anchor which will be clicked should have relative position so browser can calculate the position of the span from the parent anchor, so it will be now below the link

    • I generalized anchor and span classes, so you can use it with only one script block

    • different class has been assigned to the close button, so clicking it will click the parent anchor

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

Sidebar

Related Questions

all I want to show hide some ids using jQuery. My html code is
I am using jQuery to show/hide a div container (#pluginOptionsContainer), and load a page
I'm using this jquery code to show and hide divs on my page. As
Im using JQuery with css to show div's on a page with the Click
I'm using a placeholder span in my input fields. Using jQuery, I show/hide the
Possible Duplicate: How to show/hide a div on mouseover using jquery? I have a
I m trying to show and hide some elements(span) using jquery fadeIn and fadeOut
I am encountering an odd behavior using jQuery to show/hide a menu. I have
As the title implies, I'm using jQuery's show and hide functions to hide and
How to I hide and show HTML elements using JQuery without any special effects?

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.