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

  • Home
  • SEARCH
  • 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 8817875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:57:29+00:00 2026-06-14T04:57:29+00:00

I am facing a problem in a Jquery code. Please help me to fix

  • 0

I am facing a problem in a Jquery code. Please help me to fix this problem.

HTML Code for showing images:

<body>
    <div class="info_image">image1</div>
    <div class="info_image">image2</div>
    <div class="info_image">image3</div>

The image links with id:

    <div class="reference">
            <p><img id="image1" src="brush-seller.jpg"/></p>
            <p><img id="image2" src="Pest-seller.jpg"/></p>
            <p><img id="image3" src="pick-seller.jpg"/></p>
</body>

Now the problem is with JavaScript. I have to use .attr(‘src’,value) tag to use the image id as source and show that image in first 3 div. So far I found a code which didn’t work:

.attr('src','image/'+info_elem.find('.info_image').html())

Please help me to fix this jquery code.

  • 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-14T04:57:30+00:00Added an answer on June 14, 2026 at 4:57 am

    Use .each() to iterate over the Div’s . Fetch the html

    And use .css() to set the corresponding background image

    $('.info_image').each(function() {
        var $this = $(this);  
        var imgId = $this.html(); // Assuming the div html contains just the image ID
        var imgSrc = $('#' + imgId).attr('src');
    
        $this.css('backgroundImage','url('+ imgSrc + ')');
    })
    

    Better to use HTML5 data attribute to store the image ID instead of the html as you might need to handle the cases of empty spaces or other characters…

    <div class="info_image" data-image="image1">Here comes image1</div>
    <div class="info_image" data-image="image2">Here comes image2</div>
    <div class="info_image" data-image="image3">Here comes image3</div>
    

    Javascript

      $('.info_image').each(function() {
                var $this = $(this);  
                var imgId = $this.data('image'); 
                var imgSrc = $('#' + imgId).attr('src');
    
                $this.css('backgroundImage','url('+ imgSrc + ')');
            })
    

    This will be lot cleaner

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

Sidebar

Related Questions

This is a very weird problem am facing HTML: <input type=button id=buttonobj class=some class
Guys i am facing a problem with wildcard character in jquery. Please help if
facing a problem with html page with jquery want to show a div if
hi im new to jquery and im facing these problem i have these code
iam facing problem in passing array to view. this is my controller code.. function
i'm facing a problem tryin to execute a simples jquery inside my userControl. This
I'm facing a problem with jquery animate scrollTop to a defined div. I use
Before explaining the problem I am facing,this is the code I am using: <!DOCTYPE
I'm facing a little problem with my jQuery / Javascript code. I have several
Below are my code for jQuery UI, the problem I am facing is that

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.