|
-
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.
-
Oct 24th, 2001, 03:29 PM
#2
Thread Starter
Frenzied Member
Leave it to me to ask the question no one can answer...
My problem is, there is no good documentation.
I am finding createTextNode and appendChild and replaceChild, which sounds like a good strategy, but they deal with different objects: Element, Node, Text.
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.
-
Oct 24th, 2001, 03:54 PM
#3
Thread Starter
Frenzied Member
Ah, got it.
Element and Text objects are just types of Node objects. I think...
Code:
<html>
<head>
<script type="text/javascript">
function SetText(myText) {
var TextBlockEl = document.getElementById("TextBlock");
var NewText = document.createTextNode(myText);
TextBlockEl.replaceChild(NewText, TextBlockEl.childNodes[0]);
}
</script>
</head>
<body>
<p id="TextBlock">TSLIB</p>
<p><a href="JavaScript:SetText('Some test text.');">Some test text.</a></p>
</body>
</html>
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.
-
Oct 28th, 2001, 10:16 PM
#4
PowerPoster
Did you try just replacing the SetText(TEstText) with SetText("TestText") ?
IU noticesd you did that eventually, but maybe that was the only original prob?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 29th, 2001, 04:33 PM
#5
PowerPoster
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 1st, 2001, 12:02 PM
#6
Thread Starter
Frenzied Member
No, Sail, it is complaint with the DOM model and ECMA's mapping. If your browser has a problem with the code, then it is not a complaint browser. 
In which case, I couldn't care less.
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.
-
Nov 1st, 2001, 12:36 PM
#7
PowerPoster
LOL Me too. Basically all i work for now is IE and NS6 (little opera too). Opera has some problems with it's DOM.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Nov 1st, 2001, 12:42 PM
#8
Thread Starter
Frenzied Member
Yes, Opera has problems with anything dynamic. And I don't understand. I really really really want to ask the guys at Opera what in the hell are they smoking?
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
|