printelectric
06-16-2004, 07:18 PM
I have a very simple function that attempts to use .replaceChild to replace a piece of text within a <p> element. It works fine with .appendChild, but fails with .replaceChild. The error is:
Microsoft Jscript runtime error:
Line: 9
Char: 5
Error: Argument not optional
I am very new to Javascript, and am just trying to establish proof of concept for this to incorporate into a site that I am working on. I just ordered the JS Def. Guide this morning, but until then, if anyone can tell me in a textbooky sort of way - what my error is, and more importantly, why (what are required args. for this function, etc) - I would appreciate it +++
TIA - scott
My page is as follows - closing HTML tag removed because it was screwing up the forum CODE tags...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
<!-- hide
function changeText(){
var newText = document.createTextNode ("some new text here");
var para = document.getElementById("T1");
para.replaceChild(newText);
return false;
}
<!-- show -->
</script>
<title>jsTest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p id="T1">this is the text I want to change.</p>
<a href="#" onClick="changeText();">click me</a>
</body>
---------------------------
Microsoft Jscript runtime error:
Line: 9
Char: 5
Error: Argument not optional
I am very new to Javascript, and am just trying to establish proof of concept for this to incorporate into a site that I am working on. I just ordered the JS Def. Guide this morning, but until then, if anyone can tell me in a textbooky sort of way - what my error is, and more importantly, why (what are required args. for this function, etc) - I would appreciate it +++
TIA - scott
My page is as follows - closing HTML tag removed because it was screwing up the forum CODE tags...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
<!-- hide
function changeText(){
var newText = document.createTextNode ("some new text here");
var para = document.getElementById("T1");
para.replaceChild(newText);
return false;
}
<!-- show -->
</script>
<title>jsTest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p id="T1">this is the text I want to change.</p>
<a href="#" onClick="changeText();">click me</a>
</body>
---------------------------