@dreamcatcher:
The part that is incorrect is:
var newdiv = document.createElement('div');
This is referencing an ID of 'div' which doesn`t exist. It should be the value passed into the function, so without quotes:
var newdiv = document.createElement(div);
No, document.createElement takes a string of the element type to create ('div', 'p', 'span', etc.), not a random id value. The function addItem is taking in an parameter (div) which is the id of an existing element (note, div is not really a good variable name here, as it has clearly led to confusion... 'id' would have been a better name). Then it creates a 'div' element and copies the innerHTML of the element with the id that was passed into the function.
@durgasatya:
You can use the
W3C Validator [validator.w3.org] to validate your markup. It might not be helpful for learning what items can be nested within each other, but it will at least tell you when you have invalid markup.
Note also that the HTML specs list what items an element can contain, though this is really defined by the DTD. For example, the
TR [w3.org] element portion of the spec includes this bit taken from the DTD:
<!ELEMENT TR - O (TH|TD)+ -- table row -->
<!ATTLIST TR -- table row --
%attrs; -- %coreattrs, %i18n, %events --
%cellhalign; -- horizontal alignment in cells --
%cellvalign; -- vertical alignment in cells --
>
This part:
(TH|TD)+
means that a TR must contain a minimum of one TH or TD element. There is a pretty good
DTD Tutorial [w3schools.com] at W3Schools. Note, this is more of a low level approach. There are probably a number of good HTML books that display this information in a much more human readable format. :)