Kevin
Kevin

Reputation: 229

Linebreak in a String in JavaScript

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

Upvotes: 1

Views: 135

Answers (4)

V31
V31

Reputation: 7666

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

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

Working Fiddle

Upvotes: 0

Yaje
Yaje

Reputation: 2831

You can achieve it by doing like :

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

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

DEMO

Upvotes: 2

Abdul Jabbar
Abdul Jabbar

Reputation: 2573


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");

Upvotes: 0

Kushal
Kushal

Reputation: 1360

Try this

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

Upvotes: 1

Related Questions