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

The Archive Base Latest Questions

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

I have a div in which I am dynamically adding an image. div.append(‘<img class=prod48

  • 0

I have a div in which I am dynamically adding an image.

div.append('<img class="prod48" src="' + url + '" />');

Now the url is set by focusout of a textbox depending on the text in it. Since the append function will go on appending, how should I just change this url and not append another image in the div? The first time the focusout is called only then should I be able to append and rest times updating the url.

  • 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-18T18:14:30+00:00Added an answer on June 18, 2026 at 6:14 pm

    If you want to update the image element after it has been added to the document, you’ll have to have some way of referencing it.

    A couple of ideas come to mind immediately:

    1. Give the image a unique ID, and then use that:

      # First, change the html to include an id
      div.append('<img id="abcdef1234" class="prod48" src="' + url + '" />');
      
      #...
      # Later, grab the image by its id and change the source url
      var img = document.getElementById('abcdef1234');
      img.src = newUrl;
      
    2. Alternately, construct the image dynamically the first time, and keep the element in a variable:

      # First, create an element, and hold it in a variable:
      var img = document.createElement('img');
      img.className = "prod48";
      img.src = url;
      # Now append it to the div:
      div.append(img);
      
      #...
      # Later, we still have that element, so we can just change the source URL:
      img.src = newUrl;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a div for which i set value dynamically during run time, if
I have a div with ID 'adpictureholder', to which I dynamically add (or remove)
I have div which has three buttons as, <div id=buttons> <input id=preview class=ButtonStyle type=submit
I have div class=contentBlock which is treated as the container for updating <div class=contentBlock></div>
i have this code which creates div dynamically onclick of a button. Within div
I have a DIV which is created dynamically in javascript code with the following
I have a div tag which I populate dynamically. The problem is that in
so i have a dynamically generated set of links: <a class=linkhref=linkto/1 id=1>link 1</a> <a
I have a div within which elements are dynamically added and removed. I'd like
I have a menu div which changes height dynamically, depending on the content. The

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.