how to place a <br> in a javascriptfunction?

  • Thread starter Fjodor Klondyke
  • Start date
F

Fjodor Klondyke

hello,

i have a function in javascript. when someone clicks on a link the text in a
layer changes.
i want breaks in the text, in html you would use '<br><br>'.
i tried this in the variable that contains the text but it does not work.

so my question is: how do i get these breaks in the text, so that the text
looks
good in the layer?.

here is my code:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function toonSpelregels(spel){
if(spel == 'zappen'){
document.getElementById('spelregels').style.visibility =
'visible';
verkort = document.getElementById('spelregels').childNodes[0];
uitleg="blabla........" + "<br><br>" + " blabla....";
verkort.nodeValue=uitleg;
}

.............
.............
}

<div id="spelregels">
</div>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

thanks,

fjodor
 
L

Lasse Reichstein Nielsen

Fjodor Klondyke said:
i have a function in javascript. when someone clicks on a link the text in a
layer changes.
i want breaks in the text, in html you would use '<br><br>'.
i tried this in the variable that contains the text but it does not work.

so my question is: how do i get these breaks in the text, so that
the text looks good in the layer?.

You use br elements.
Plain text has no formatting, so if you want formatting, you need to add
more than just plain text.


var verkort = document.getElementById('spelregels');
verkort.style.visibility="visible";
// clear verkort
while (verkort.hasChildNodes()) {
verkort.removeChild(verkort.lastChild);
}
//insert new nodes
verkort.appendChild(document.createTextNode("blabla......."));
verkort.appendChild(document.createElement("br"));
verkort.appendChild(document.createElement("br"));
verkort.appendChild(document.createTextNode("blabal...."));

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top