1

I want to make a linkebreak in a String. In HTML it's like this (if I replace the T with a linkebreak): mystring.replace("T", "<br>");

But this doesn't work in JavaScript. The <br> is part of the String too. How do I implement this in JavaScript? Thanks!

mystring BEFORE linkebreak:

2013-10-22T22:56:25.534Z

mystring AFTER linebreak:

2013-10-22T

22:56:25.534Z

3
  • 4
    That depends on where you are putting the string. Are you putting it in a console.log? In an alert? In the DOM itself? In a text file? Commented Aug 18, 2014 at 9:19
  • 2
    if you want T also why are you replacing it? Commented Aug 18, 2014 at 9:19
  • Hi everyone. Thanks for your replies. 'mystring.replace("T", "T\n");' works pretty well. It works in 'alert' and in 'console.log' as well. Unfortunately, it doesn't work for me, because I use a rickshaw diagram and I try to put this String as a x-axis label. It doesn't work because of the rickshaw library, but that's another topic. Thank you! Commented Aug 18, 2014 at 9:43

4 Answers 4

2

You can achieve it by doing like :

var mystring = "2013-10-22T22:56:25.534Z";

console.log(mystring.replace("T", "\n"));

DEMO

Sign up to request clarification or add additional context in comments.

Comments

1

Try this

"2013-10-22T22:56:25.534Z".replace("T", "\n");

1 Comment

I think it would be more helpful for the OP and further visitors, when you add some explaination to your intension.
0


is used for html, in javascript normal new line character '\n' will do the trick, so you need to replace T with this new line character '\n' rather than

mystring.replace("T", "\n");

Comments

0

If you want the T in your statement you can do something like

mystring = mystring.replace(/T/, "T\n");

Working Fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.