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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:25:50+00:00 2026-06-01T00:25:50+00:00

I have a variable myvar = document.getElementById(‘myid’).innerHTML that I would like to replace all

  • 0

I have a variable myvar = document.getElementById('myid').innerHTML that I would like to replace all of the images in with their corresponding src attribute using JavaScript.

EDIT: Sorry for the confusion! I was trying to be succinct, time being precious and all – apparently I failed.

To borrow from Jon’s interpretation:

I want to store all elements with the id of myid in myvar and then iterate through them to change all of them to plain text – the plain text being the value of their src attributes.

Here is an example of what I would like to achieve.

I start with something like this:

<img src="someimage.png"><br>
Lorem ipsum dolor sit amet<br>
<img src="anotherimage.jpg"><br>
Lorem ipsum dolor sit amet

And it would translate to:

someimage.png<br>
Lorem ipsum dolor sit amet<br>
anotherimage.jpg<br>
Lorem ipsum dolor sit amet
  • 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-01T00:25:51+00:00Added an answer on June 1, 2026 at 12:25 am

    Seems everyone missed what you were asking, perhaps you’ve “clarified” the question. This should suit:

    var image, images = document.images;
    var i = images.length;
    
    while (i--) {
      image = images[i];
      image.parentNode.replaceChild(document.createTextNode(image.src), image);
    }
    

    It will replace all the images in the document with a text node of their src property value. Note that as you replace each element, the images collection will get shorter, hence the backward loop. You could also do:

    while (images.length) { 
      image = images[0];
      image.parentNode.replaceChild(document.createTextNode(image.src), image);
    }
    

    If you want to restrict it to just the images inside a paricular element, get a reference to the element and create images as a NodeList using element.getElementsByTagName('img');

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

Sidebar

Related Questions

I have a conversationScope.myVar=myValue variable; I would like to use it inside a mybatis
I have defined the following variable: myVar=true now I'd like to run something along
I have an object variable that has several properties. MyVar = {prop1 : 0,
I have a function name stored in a variable like this: myvar = 'mypackage.mymodule.myfunction'
I have a variable foo that contains a time, lets say 4pm today, but
I have a variable in my xsl that may or may not be declared.
I have a variable that im define with another variable and some text. $title
Say I have an environment variable myvar : myvar=\tapple\n When the following command will
I have several queues that all extend a Queue class. I want to do
I have the following function, but I can't seem to get the myVar variable

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.