www.webdeveloper.com
Results 1 to 6 of 6

Thread: how can I add a line break to this?

  1. #1
    Join Date
    Jun 2004
    Posts
    133

    Question how can I add a line break to this?

    I want to add line breaks to the text messages. My \n is being ignored. Please help. Thanks.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html><head><title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    #wrap{width:500px;padding:10px;border:0px;
    font-family:"Times New Roman",Times,serif;
    font-size:12pt;text-align:center;margin:10px auto;}
    #message{height:1%;color:#9b0a0a;filter:alpha(opacity=0);opacity:0;}
    </style>
    <script type="text/javascript">
    /*
    Code Title: Dissolve Text
    Author: Raymond Angana
    Created: August 14, 2008
    rangana in dynamicdrive.com/forums
    This notice must stay intact for legal use
    */
    var txt=['"Quote One" \n -John Smith','"Quote Two" \n -Jane Doe'],
    init=0,i=0,k=0,speed=20,el;
    function fade(){
    init==0?i++:i--;
    el.filters?el.style.filter='alpha(opacity='+i+')':el.style.opacity=i/100;
    el.firstChild.nodeValue=txt[k];
    if(i==100)init=1;
    if(i==0) {init=0;k++;}
    if(k==txt.length)k=0;
    setTimeout('fade()',speed);}
    window.onload=function(){el=document.getElementById('message');fade();}
    </script>
    </head><body><div id="wrap"><div id="message">&nbsp;</div></div></body></html>

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    \n doesn't work in HTML, use <br>.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  3. #3
    Join Date
    Jun 2004
    Posts
    133
    Quote Originally Posted by Logic Ali View Post
    \n doesn't work in HTML, use <br>.
    Forgot to mention, I tried that also. It shows up actually as <br> rather than making a break.

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,252
    Try an el.firstNode.innerHTML or build textNodes and a br element with createElement

  5. #5
    Join Date
    Jun 2004
    Posts
    133
    Quote Originally Posted by 007Julien View Post
    Try an el.firstNode.innerHTML or build textNodes and a br element with createElement
    I'm a bit too much of a java newbie to be able to figure out how to make this work, but I appreciate you trying to help. Thanks.

  6. #6
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,252
    Try this
    Code:
    <script type="text/javascript">
    
    var txt=['"Quote One"<br>-John Smith','"Quote Two"<br>-Jane Doe'],
    fadeInOut=0,fadeStep=0,txtItem=0,speed=20,elm;
    function fade(){
    	fadeInOut==0?fadeStep++:fadeStep--;
    	elm.filters?elm.style.filter='alpha(opacity='+fadeStep+')':elm.style.opacity=fadeStep/100;
    	if(fadeStep==100) fadeInOut=1;
    	if(fadeStep==0) {fadeInOut=0;txtItem++;txtItem%=txt.length;
    		elm.innerHTML=txt[txtItem];}
    	
    	setTimeout(fade,speed);
    }
    window.onload=function(){elm=document.getElementById('message');elm.innerHTML=txt[txtItem];fade();}
    </script>
    We change the message only with k

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles