Solved

A way to do an \n or \r\n when writing value in textLine.nodeValue??

Posted on 2011-10-01
4
226 Views
Last Modified: 2012-05-12
Is there a way to do an \n or \r\n or such when writing value in textLine.nodeValue??

Since innerHTML is not recommended to use anymore when dealing with nodeValues.

Thanx.
0
Comment
Question by:walkman69
  • 3
4 Comments
 

Expert Comment

by:cooooolio
ID: 36895992
Use <pre> in wrapping tag
for example
<span id="span_id_xxxx"><pre> \r\n  \r\n</pre></span>
0
 
LVL 2

Author Comment

by:walkman69
ID: 36897940
Cooooolio:

It sounded like it could work..

But i tried doing it this way:


	var templateDescriptionText = document.createElement('p');
	templateDescriptionText.setAttribute('class', 'templateDescriptionText');
	templateDescriptionText.setAttribute('id', 'templateDescriptionText_1');

	var newTextNodeWrapper = document.createElement('pre');	

	newTextNode = document.createTextNode('');
	templateDescriptionText.appendChild(newTextNode);	
	
	newTextNodeWrapper.appendChild(templateDescriptionText);		
	
	templateDescription.appendChild(newTextNodeWrapper);	

Open in new window




But it still generates the text \r\n in the <p>-tag..

I also tried putting the <pre></pre> inside of templateDescriptionText, and changed the id to be on the <pre> instead so that the text would be written to it's child (the newTextNode) instead of to the <p>.

Still didn't work.. It looks like the structure you suggested when i look up html-structure in Firefox firebug, have I done anything incorrectly? Would be great if you could post a brief example (javascript).



0
 
LVL 2

Accepted Solution

by:
walkman69 earned 0 total points
ID: 36898095
However I found that just doing a regular carriage return in the XML-document made the text
newline as it should. However it would be nice if \r\n could work to. But I guess I can't get everything.
Or can I?... =)
0
 
LVL 2

Author Closing Comment

by:walkman69
ID: 37433184
Altough not fully optimized for my needs. This solution come closest to the solution I was looking for.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question