• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

14. Creating Dynamic Content > 14.9. Creating a New Element

Creating a New Element

NN 6, IE 5

Problem

You want to generate a brand new element and insert it into the body of the current page.

Solution

For IE 5 or later and Netscape 6 or later, use the W3C DOM element-creation method of the document object. The sole parameter is a string of the tag name for the element:

var elem = document.createElement("p");

You can now populate the element with properties and other content, and then insert it into the document.

Discussion

The tag name you supply as a parameter to the createElement( ) method can be upper- or lowercase, but in keeping with current trends in XHTML practice, lowercase is the preferred style. Your case choice does not influence the value returned by the element’s tagName property, which uniformly returns values in all uppercase.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint