INFO: The Difference Between the <DIV> and <SPAN> HTML TagsID: Q180153
|
This article describes the difference between the <DIV> and <SPAN> HTML tags, which are available in Internet Explorer 4.0x.
The <DIV> tag is a block element used for creating a container to hold and position other elements. It is commonly used for absolute positioning of content.
The <SPAN> tag is an inline element used to render text using a style
sheet. It is commonly used to change the style of an element or text within
a sentence or block such as <P>, <DIV> or <TABLE>.
Because the <SPAN> tag cannot create a line break, the following HTML will not behave as expected:
<HTML>
<HEAD>
<SCRIPT>
function DoStuff()
{
txt.innerHTML = "<UL><LI>It worked</UL>";
}
</SCRIPT>
</HEAD>
<BODY>
<P>
<SPAN ID=txt>HTML<b> to be</b> replaced</SPAN>
</P>
<A HREF="javascript:DoStuff()">Click Me</A>
</BODY>
</HTML>
This use of the innerHTML property will succeed if you replace the <SPAN> tag pair with <DIV>.
For more information, please see the MSDN Web Workshop:
http://msdn.microsoft.com/workshop/default.asp
Additional query words:
Keywords : kbDSupport AXSDKIEScripting
Version : WINDOWS:4.0,4.01
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: July 23, 1999