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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:41:58+00:00 2026-05-20T14:41:58+00:00

Rather than trying to create tons of different pages on my website, I’m trying

  • 0

Rather than trying to create tons of different pages on my website, I’m trying to update the content of a single div when different items in the navbar are click to update the maint div content. I tried to find a simple example using Javascript:

        <script type="text/javascript">
            function ReplaceContentInContainer(id,content) {
                var container = document.getElementById(id);
                container.innerHTML = content;
            }
        </script>


          <div id="example1div" style="border-style:solid; padding:10px; text-align:center;">
            I will be replaced when you click.
        </div>
        <a href="javascript:ReplaceContentInContainer('example1div', '<img src='2.jpg'>' )">
            Click me to replace the content in the container.
        </a>

This works just fine when I only try and update text, but when I put an img tag in there, as you can see, it stops working.

Either
1) what is the problem with how I am trying to do it?
or 2) What is a better/easier way to do it?

I’m not stuck on Javascript. jQuery would work too, as long as it is just as simple or easy. I want to create a function that will just let me pass in whatever HTML I want to update and insert it into the div tag and take out the ‘old’ HTML.

  • 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-20T14:41:59+00:00Added an answer on May 20, 2026 at 2:41 pm

    You just have some escaping issues:

    ReplaceContentInContainer('example1div', '<img src='2.jpg'>')
                                                       ^     ^
    

    The inner ' need to be escaped, otherwise the JS engine will see ReplaceContentInContainer('example1div', '<img src=' plus some syntax errors resulting from the subsequent 2.jpg'>'). Change the call to (tip of the hat to cHao’ answer concerning escaping the < and > in the HTML):

    ReplaceContentInContainer('example1div', '&lt;img src=\'2.jpg\'&gt;')
    

    A simple way to do this with jQuery would be to add an ID to your link (say, “idOfA”), then use the html() function (this is more cross-platform than using innerHTML):

    <script type="text/javascript">
        $('#idOfA').click(function() {
            $('#example1div').html('<img src="2.jpg">');
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

rather than using a textnode to show content im trying to figure out how
I'm trying to create an association between two models using join conditions rather than
Im trying to create a browser popup window with some text, rather than using
I'm trying to find open source profilers rather than using one of the commercial
I'm trying to get fastercsv setup so that rather than parsing each row, it
I'm trying to make an asterisk line up vertically with surrounding text/graphics rather than
I'm trying to modify the icons for the jQuery UI portlets . Rather than
Based on this question which was closed rather quickly: Trying to create a program
I'm trying to create a workflow bar on a web page. The items in
I'm trying to create an HTML form (using JSP) which contains Javascript buttons (rather

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.