How can i create html elements dynamically?

First of all i'm still in the learning process and slowly trying to push myself to the next level in web development so please help me
I'm making a small word document maker, it can make text dynamically and insert images dynamically too. but i cannot use a simple text area because i want to make it dynamically. i cannot insert images with a textbox. So i decided to make an iframe and made another html tag inside of it for the work area and i was planning to make the text and the inserting of images dynamically inside the iframe>html. But I don't have a clue and an idea how to do this. i know its possible creating the text and inserting images there but I don't know how to build them dynamically. I was thinking while typing its inserting html elements like paragraph tags and such.. can anyone help or give me an idea?


  • Hi,

    First of all I wouldn't use an iFrame. You can use a div tag and set contenteditable to true. Now you can edit the contents of the div.


    To dynamically create an element you can use the createElement method of the document object:
    var img = document.createElement('img');
    img.src = 'myImage.jpg'

    After you created a new img tag you have to insert it in your document. That's what appendChild does. You could also insert it in your div with this code:

    Hope you find this usefull

    the Netherlands...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion