Javascript DOM createElement method provides the functionality to create the span element at runtime of HTML web page. You can insert the new span tag into the HTML body or any previously created static HTML element in the body of HTML document such as <div> tag or paragraph <p> tag. createElement accepts the parameter as HTML element name e.g. span and creates its Javascript object. You can access the various properties and methods of the dynamically created span tag such as style function and its properties, id property, title property. Also you can alter the innerText or innerHTML of the span tag dynamically. Javascript DOM appendChild method enables you to add the newly created element into the HTML body element or nay other HTML element by accessing it using document.getElementById.
<html xmlns="http://www.w3.org/1999/xhtml" > <head>
<head>
<title>Javascript Create Span</title>
<style type="text/css">
.dynamicSpan {
font-size:11px; font-family:verdana; color:Orange;
</style>
<script type="text/javascript" language="javascript">
{
document.body.appendChild(spanTag);
}
</head><
</body> </html>
</html>
Output
This HTML Span tag is created by using Javascript DOM dynamically.
Above example shows the use createElement method of Javascript DOM that provides the functionality to create the span tag dynamically and append the HTML body tag by passing the spanTag object to the appendChild function to insert the new child element.
Currently rated 5.0 by 1 people
Tags: javascript, dom, html, javascript create span, javascript createelement, html span tag, html div tag, javascript appendchild, javascript innertext, javascript innerhtml, dhtml, dynamic html, javascript document object, javascript create span dynamically
8/23/2008 9:03:02 PM