Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15350

How to create nested elements with createElement(...)?

From Tuxedo <tuxedo@mailinator.com>
Newsgroups comp.lang.javascript
Subject How to create nested elements with createElement(...)?
Date 2012-08-13 22:19 +0200
Organization albasani.net
Message-ID <k0bng9$8it$1@news.albasani.net> (permalink)

Show all headers | View raw


This appends an image to the body:

function appendElement(){
var img = document.createElement("img");
img.src = 'image.png';
document.body.appendChild(img);
}

How can the same function be made also to create a <div>, so that the div 
contains the image, or for a div to be appended to the body and for the 
image to be appended to appear within the div?

Many thanks for any advise,
Tuxedo

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

How to create nested elements with createElement(...)? Tuxedo <tuxedo@mailinator.com> - 2012-08-13 22:19 +0200
  Re: How to create nested elements with createElement(...)? "Tom de Neef" <tdeneef@qolor.nl> - 2012-08-13 23:06 +0200
  Re: How to create nested elements with createElement(...)? Andrew Poulos <ap_prog@hotmail.com> - 2012-08-14 07:08 +1000
    Re: How to create nested elements with createElement(...)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-16 03:42 +0200

csiph-web