Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    77
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question /n to be converted into br tag

    I have a string which contains \n.I want that to be rendered as a <br>new lew line .
    I have a code written for a perticular div:
    Code:
    $(function(){
    	 var str = $('.brk').text().replace(/\\n/g,"<br/>");
    	 $('.brk').html(str);
    });
    	
    <td colspan="2" class="main_sub_title_black brk" style="padding:0;">
    		<!--s:property value='titleInstruction' escape='false'/-->
    		
    In addition to Username and Password, an Authentication Code is required to access Merlin.net. Follow these steps to complete the login process:\n\n 1. Select the delivery method to receive an Authentication Code.\n 2. Press "Get Authentication Code" and receive a code through the selected method.\n 3. Enter the received Authentication Code and press "Continue"
    
    </td>
    but there may be multiple divs with .brk class and they may contain \n in the string.
    How to resolve that issue?

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,678
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    Does this help?

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    77
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    Does this help?

    Hi,
    It din't work for me . It's showing allthe strings in 1 div only(i.e in .brk div)

  • #4
    New Coder
    Join Date
    Feb 2007
    Posts
    77
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Hey I got the solution.
    I iterated through the div with class .brk
    $(".brk").each(function()
    {
    var oldText = $(this).text();
    var newText = oldText.replace(/\\n/g, "<br />");
    $(this).html(newText);
    });


    But, thanks for your help

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Glad you figure it out by yourself. But I was wondering why you don't convert the newlines from the backend? Doing it in the frontend is slow and causes "flicker".


  •  

    Posting Permissions

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