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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:06:55+00:00 2026-06-07T04:06:55+00:00

I try to accomplish a list of elements on which you hover a different

  • 0

I try to accomplish a list of elements on which you hover a different image are displayed.

Something like this

<ul id="test">
 <li id="sidebarList_1">Image 1</li>
 <li id="sidebarList_2">Image 2</li>
 <li id="sidebarList_3">Image 3</li>
<ul>


<div id="imgDiv_1">
    <img src="http://www.freemacware.com/wp-content/images/smultron1.png" />
</div>
<div id="imgDiv_2">
    <img src="http://www.freemacware.com/wp-content/images/smultron2.png" />
</div>
<div id="imgDiv_3">
    <img src="http://www.freemacware.com/wp-content/images/smultron3.png" />
</div>

My jQuery looks like this

$(this).mouseover(function() {
    $("#imgDiv_1").css('visibility','visible'); 
}),

$(this).mouseout(function() { 
    $("#imgDiv_1").css('visibility','hidden'); 
});

As seen it is static as it is now. I tried something like this to get the number of the id element in the li (ex sidebarList_1):

$(this).mouseover(function() {   
    var myString = $(this).val().split("_").pop();   
    $("#imgDiv_" + myString).css('visibility','visible'); 
}),

$(this).mouseout(function() { 
    var myString = $(this).val().split("_").pop();
    $("#imgDiv_" + myString).css('visibility','hidden'); 
});

​But this does’nt work. How can I accomplish what Im trying to do?

  • 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-07T04:06:56+00:00Added an answer on June 7, 2026 at 4:06 am

    I would add a data-* attribute to your li elements, whose value corresponds to the relevant div:

    <ul id="test">
     <li id="sidebarList_1" data-img="imgDiv_1">Image 1</li>
     <li id="sidebarList_2" data-img="imgDiv_2">Image 2</li>
     <li id="sidebarList_3" data-img="imgDiv_3">Image 3</li>
    <ul>
    

    And then use the following jQuery:

    $("#test").on("mouseover mouseout", "li", function () {
        $("#" + $(this).data("img")).toggle();
    });​
    

    Here’s a working example.

    This uses the on method, with a selector as the second argument, to take advantange of event delegtation (there’s only one event handler instead of one for each li element). It assumes that the div elements are hidden by default, so on mouseover, the toggle call will make the hovered div visible.

    Useful references

    • The .on() method
    • The .toggle() method
    • The .data() method
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is just an example code of the thing i try to accomplish. String
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
try: recursive_function() except RuntimeError e: # is this a max. recursion depth exceeded exception?
Try to see which cast is faster (not necessary better): new c++ case or
What I'm trying to accomplish with this code is, first it scans a directory
I have a list of tuples like a = [(1, 2), (2, 2), (3,
My site has urls like 'http://someRandomUsername.mysite.com'. Sometimes users will try urls like 'http://www.someRandomeUsername.mysite.com'. I'd
I'm developing my first ASP.NET MVC app and what I'd like to accomplish is
Let me try this again, I'm going to leave out the exact data/example and

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.