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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:34:34+00:00 2026-06-04T21:34:34+00:00

Im trying to do some basic stuff with javascript, to get it to generate

  • 0

Im trying to do some basic stuff with javascript, to get it to generate some website content automatically,, but its driving me crazy!!! Could someone please show me a simple example of how to do get javascript to create new images and paragraphs in divs.. lets say my website structure is like this…

<html>
<head>
</head>

<body>
<div id ="wrapper">
<div id ="content">
</div>
</div>
</body>
</html

how would I use a javascript function to create images and paragraghs in the “content” div on-loading the page and also on-clicking an image. I know it has to with the DOM but Ive been at this for hours and I just cant get it to work! Please show me an example of how its done. Thanks a lot in advance!!!!!!

  • 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-04T21:34:35+00:00Added an answer on June 4, 2026 at 9:34 pm

    In its simplest form:

    // gets a reference to the div of id="content":
    var div = document.getElementById('content'),
        // creates a new img element:
        img = document.createElement('img'),
        // creates a new p element:
        p = document.createElement('p'),
        // creates a new text-node:
        text = document.createTextNode('some text in the newly created text-node.');
    
    // sets the src attribute of the newly-created image element:
    img.src = 'http://lorempixel.com/400/200/people';
    
    // appends the text-node to the newly-created p element:
    p.appendChild(text);
    
    // appends the newly-created image to the div (that we found above):
    div.appendChild(img);
    // appends the newly-created p element to the same div:
    div.appendChild(p);
    

    JS Fiddle demo.

    References:

    • element.appendChild().
    • document.createElement().
    • document.createTextNode().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to rewrite links with .htaccess file. Basic stuff, but for some
So I'm trying to do some basic stuff with databases and graphs. I've gotten
I am new to Corona and am trying to get some basic OOP going
I am trying to get my head round some basic erlang functionality and I
I am using Lucene 3.5.0 to do some basic search stuff on my website.
I'm trying to get deeper into advanced-SQL'ing but have a slight problem with some
I'm trying to do some basic quartz core drawing with arcs, but have an
Trying to do some really basic math here, but my lack of understanding of
I'm trying to do some really simple stuff in C++, but I can't find
I'm trying to get some basic ajax working on rails. I have a comon

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.