Forum Moderators: open
After creating the table, then only <script> tag is working inside this code.
That's way second "hello" which is inside the external javascript, getting outside of the table. It happens only in IE browsers.
How do I make it second "Hello" inside of the table.
// test.htm
<html>
<head>
<title>Untitled Page</title>
</head>
<body>
<script language="javascript" type="text/javascript" src="test1.js"></script>
</body>
</html>
// test1.js
document.write('<table cellpadding="0" cellspacing="0" border="1" bordercolor="red">');
document.write(' <tr>');
document.write(' <td>');
document.write(' Hello');
document.write(' </td>');
document.write(' <td>');
document.write(' <script type="text/javascript" src="test2.js"></script>');
document.write(' </td>');
document.write(' </tr>');
document.write('</table>');
document.write('<br><br>');
//test2.js
document.write('Hello');
The document.write method provides a way of incorporating strings into the HTML content of the page. There are better ways to do that, such as .innerHTML and .createElement or HTML cloning patterns. Use of document.write should be avoided.document.write is recklessly dependent on timing. If document.write is called before the onload event, it appends or inserts text into the page. If it is called after onload, it completely replaces the page, destroying what came before.
document.write encourages bad structure, in which script and markup are intermingled. A cleaner structure has minimal interaction between markup and script.
Also, you should not be relying on JavaScript to write your content.
[edited by: Fotiman at 3:34 pm (utc) on Dec. 20, 2006]