Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.nodeValue Line Breaks?

Status
Not open for further replies.

nicoliver

Technical User
Apr 15, 2002
5
0
0
AU
Hi
I'm trying to work out how to include a line break within this javascript printing..
At the moment i have the line:

document.getElementById('help').childNodes[0].nodeValue = 'line 1 line 2';

I've tried all the HTML tags to place a line break but it won't do it. I have a feeling it's due to the .nodeValue but i'm not 100% sure.
If someone could suggest something it would be much appreciated...
Thanks
Nic
 
You'll have to add a new node (a BR element), and then your second line of text. That, or use innerHTML instead:

Code:
document.getElementById('help').childNodes[0].innerHTML = 'line 1<br>line 2';

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hey Dan
Thanks for that. I tried to switch the .nodeValue with .innerHTML but the command failed to work atall. I think i must have been missing some definition of HTML? The entire JS snippet is:

-----------------------------------------------

<script language="javascript">
function show(id) {
if (id==1) {
document.getElementById('help').childNodes[0].nodeValue = 'line 1 line 2';
}
if (id==2) {
document.getElementById('help').childNodes[0].nodeValue = 'Section 2';
}
if (id==3) {
document.getElementById('help').childNodes[0].nodeValue = 'Section 3';
}
}
</script>

-----------------------------------------------

If i change .nodeValue to innerHTML the command fails to execute.

Do you have any other suggestions?

Thanks again
nic
 
Hi Dan,
I'm not too familiar in JS so i'm not sure which nodetype it is.
The script is basically to change the text in a DIV by using a button with ID's for support. So each time a user clicks a ? they get the specific support text for that item.

Only thing is, on some bits of text it really needs to be split onto lines. Hence wanting line breaks.

Sorry about the lack of help with that.. If you have any suggestions i'm poised ready to try them!

Thanks
Nic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top