Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break line in JavaScript?

Tags:

Please let me know how to break line in JavaScript.

<input type='submit' name='Submit' value='Submit' 
onClick="parent.location='mailto:[email protected]?subject=Thanks for writing to me &body=I will get back to you soon. Thanks and Regards Saurav Kumar'">

I want a break line in Subject. The output I need is:

I will get back to you soon
Thanks and Regards
Saurav Kumar
like image 851
saurav2109 Avatar asked Jan 22 '11 13:01

saurav2109


People also ask

What is br /> in JavaScript?

To create a line break in JavaScript, use “<br>”. With this, we can add more than one line break also.

How break JavaScript code into multiple lines?

There are two ways to break JavaScript code into several lines: We can use the newline escape character i.e “\n”. if we are working on the js file or not rendering the code to the html page. We can use the <br> tag.

How do you insert a break in line?

To add spacing between lines or paragraphs of text in a cell, use a keyboard shortcut to add a new line. Click the location where you want to break the line. Press ALT+ENTER to insert the line break.

How do you break a line in typescript?

“typescript break string new line” Code Answer's //with the \n character.


2 Answers

Add %0D%0A to any place you want to encode a line break on the URL.

  • %0D is a carriage return character
  • %0A is a line break character

This is the new line sequence on windows machines, though not the same on linux and macs, should work in both.

If you want a linebreak in actual javascript, use the \n escape sequence.


onClick="parent.location='mailto:[email protected]?subject=Thanks for writing to me &body=I will get back to you soon.%0D%0AThanks and Regards%0D%0ASaurav Kumar'
like image 152
Oded Avatar answered Oct 09 '22 00:10

Oded


Here you are ;-)

<script type="text/javascript">
    alert("Hello there.\nI am on a second line ;-)")
</script>
like image 24
Andreyco Avatar answered Oct 09 '22 01:10

Andreyco