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

The Archive Base Latest Questions

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

The following code is given by one of user and friend on stackoverflow as

  • 0

The following code is given by one of user and friend on stackoverflow as solution for my problem.
HTML Code

<img src="https://s3.amazonaws.com/twitter_production/a/1265328866/images/twitter_logo_header.png"/>

<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>

<div class="sample">
  <img src="http://sstatic.net/so/img/logo.png">
  <img src="http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif">
  <img src="http://cacm.acm.org/images/logo.ACM.gif">
  <img src="http://static03.linkedin.com/img/logos/logo_linkedin_88x22.png">
</div>

JQUERY Code

$(function () {
    var textboxes = $("input:text"), //gets all the textboxes         
        images = $(".sample img");   //gets all the images

    images.not(":first").hide(); //hide all of them except the first one
    textboxes.each(function (i) {
        var j = i;
        $(this).focus(function () {
            images.hide().eq(j).show();
        });
    });
});

The above code shows image related to text box which has focus and hides rest of the all three images at the same time.

The above process goes on sequentially that is for first text box first image is visible, for second text box send image is visible in this way.
Now the problem is I want to show 1. when focus comes to first text box first image is visible
2. When focus comes to second text box second image is visible
3. when focus comes to third text box i want the second image as it is visible
in this way after 4 and fifth text box when sixth text box comes again the third image should be visible.

QUE 1. Is it possible to show the image as i want but using loop as in above code and identifying the text box using jquery? or i have to write seperate functions for each text box?

There is not only the text boxes but also group of radio buttons, select boxes, and group of check boxes too in between text boxes so when focus comes to these radio buttons or select boxes or check boxes the related image to them should get visible. so

Que 2. How can I distinguish between the images for above controle ?

Que 3. what following line will do in the code and How its get executed means which function is executed first then which second in this way?
images.hide().eq(j).show();

Please reply for above questions as in depth as you can because i am new to jquery. and i want to know how it works
Thank You

  • 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-13T17:16:20+00:00Added an answer on May 13, 2026 at 5:16 pm

    I’m having a hard time understanding what you say, but if i understood correctly, you have a series of inputs (input, select, textarea…) matching a series of images. You want to control the show/hide behaviour of images according to which input has focus.

    The way you can solve this is in the relation you set programmatically in the DOM between the images and the inputs. Right now, you use the order of appearance for that. It can work but you’ll have to remember in six-months during maintenance to respect that invisible rule.

    Therefore I would propose another option, more semantic and readable: using classes and ids. Inputs and images having to go together would share a common identificator number (ex: <input id="input-5" type="text"/> for your inputs, <img id="image-5" src="path.jpg"/> for your images, and then reconstruct the selector in your each() function, using the identification number.

    The jquery would be something in the likes:

    $(function () {
    
    $('.image').hide();
    
    $('input').focus(function(){
      var parts= $(this).attr('id').split('-');
      var uId = parts[1];
      alert(uId);
      // now, find the right image to show
      $('.image').hide();
      $('#image-'+uId).show();
    
    });
    });
    

    You can see a live example here (you can play with it here).

    Tell me if i’m on the right track or if i completely misunderstood your need. If i’m on the right track, we will be able to solve your remaining issues by completing this logic.

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

Sidebar

Related Questions

Problem One friend suggested an interesting problem. Given the following code: public class OuterClass
Assume that the following Perl code is given: my $user_supplied_string = &retrieved_from_untrusted_user(); $user_supplied_string =~
Given the following code: $(.force-selection).blur(function() { var value = $('matched-item').val(); //check if the input's
Given the following code: final class retVal { int photo_id; } Gson gson =
Given the following code: function Person(firstName, lastName) { this.FirstName = firstName; this.LastName = lastName;
Given the following code. EventLoopScheduler scheduler = new EventLoopScheduler(ts => new Thread(ts)); BehaviorSubject<int> subject
Given the following code below, how can I have it modified such that it
Given the following code: string source = Some Unicode String; foreach( char value in
Given the following code, is there a way I can call class A's version
Given the following code $c= new SoapClient('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'); $usa = USD; $eng = GBP; doing

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.