|
-
Oct 24th, 2001, 12:24 PM
#1
Thread Starter
Frenzied Member
JavaScript: Replacing Text
Okay, this code doesn't work.
Code:
<html>
<head>
<script type="text/javascript">
function SetText(myText) {
var TargetEl = document.getElementById("TextBlock");
TargetEl.replaceWholeText(myText);
}
var TestText = "Some test text.";
</script>
</head>
<body>
<p id="TextBlock">TSLIB</p>
<p><a href="JavaScript:SetText(TestText);">Some test text.</a></p>
</body>
</html>
First, don't complain about the use of the anchor tag. I'm not too keen on using it either, but it works. 
Second, I'm sure there is a better way to do this, but I'm trying to understand this method. If you have a different way, I'm interested, but I want to make this way work, too.
Now, the replaceWholeText method is part of the Text object. At this point, TargetEl is an Element Object. So how does name space work? How can I grab this element/node in such a way that I can replace it's text?
Documentation helps, thanks.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|