Update:
ECMAScript 6 (ES6) introduces a new type of literal, namely template literals. They have many features, variable interpolation among others, but most importantly for this question, they can be multiline.
A template literal is delimited by backticks:
var html = ` <div> <span>Some HTML here</span> </div> `;
(Note: I’m not advocating to use HTML in strings)
Browser support is OK, but you can use transpilers to be more compatible.
Original ES5 answer:
Javascript doesn’t have a here-document syntax. You can escape the literal newline, however, which comes close:
"foo \ bar"
Related Posts:
- Creating multiline strings in JavaScript
- How to check whether a string contains a substring in JavaScript?
- Check if a string has a certain piece of text [duplicate]
- How to convert a string to an integer in JavaScript?
- How can I do string interpolation in JavaScript?
- How do I make the first letter of a string uppercase in JavaScript?
- How do I make the first letter of a string uppercase in JavaScript?
- Split string into array
- How do you reverse a string in-place in JavaScript?
- What is the correct way to check for string equality in JavaScript?
- Check if a variable is a string in JavaScript
- What’s the best way to convert a number to a string in JavaScript?
- Check if a variable is a string in JavaScript
- How can I remove a character from a string using JavaScript?
- How to print elements from array with javascript
- How to remove text from a string?
- What does ${} (dollar sign and curly braces) mean in a string in Javascript?
- Delete first character of a string in Javascript
- ES6: Create Strings using Template Literals – Freecodecamp
- How do I check if string contains substring? [duplicate]
- How do I check if string contains substring?
- How can I get the last character in a string?
- How can I get the last character in a string?
- Count the number of occurrences of a character in a string in Javascript
- Converting an object to a string
- Anagrams finder in javascript
- How to interpolate variables in strings in JavaScript, without concatenation?
- How can I extract a number from a string in JavaScript?
- String.Format not work in TypeScript
- How to do case insensitive string comparison?
- How to remove part of a string?
- Escaping HTML strings with jQuery
- Replace all spaces in a string with ‘+’
- How to count string occurrence in string?
- Insert a string at a specific index
- Strip HTML from Text JavaScript
- Strip all non-numeric characters from string in JavaScript
- Wildcard string comparison in Javascript
- Replace spaces with dashes and make all letters lower-case
- Check if a JavaScript string is a URL
- How do you check that a number is NaN in JavaScript?
- JQuery – $ is not defined
- Client on Node.js: Uncaught ReferenceError: require is not defined
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general?
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- How to import jquery using ES6 syntax?
- How to filter an array/object by checking multiple values
- Does JavaScript pass by reference? [duplicate]
- How to resolve the C:\fakepath?
- How to pass props to {this.props.children}
- Adding options to select with javascript
- MRAID file reference
- How to format numbers?
- RegExp in TypeScript
- How to use searchFile and searchFolder at the same time correctly? – App Script
- node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]
- Get the value of checked checkbox?
- Equivalent of jQuery .hide() to set visibility: hidden
- Create table using Javascript
- Parse an HTML string with JS
- JS file gets a net::ERR_ABORTED 404 (Not Found)
- Shortest way to print current year in a website
- push object into array
- module.exports “Module is not defined”
- Why doesn’t JavaScript support multithreading?
- plain count up timer in javascript
- Uncaught TypeError: Cannot read property ‘name’ of undefined
- How to calculate date difference in JavaScript?
- Finding the average of an array using JS
- Is it possible to simulate key press events programmatically?
- Vue template or render function not defined yet I am using neither?
- Cannot read property ‘length’ of null (javascript)
- Caesar Cipher in Javascript
- Return array from function
- Why define an anonymous function and pass it jQuery as the argument?
- Error parsing XHTML: The content of elements must consist of well-formed character data or markup
- How to scroll an HTML page to a given anchor
- Javascript call() & apply() vs bind()?
- what is the best way to check variable type in javascript
- JavaScript Array Push key value
- stopPropagation vs. stopImmediatePropagation
- How to replace regular jquery calls with CDN calls from Google?
- Editing Source Code in WordPress
- How/Where is editor.min.js Added to the wp-admin Post Page?
- Close TinyMCE plugin window on click away
- Script Localization doesn’t work
- How to conditionally show/hide controls & sections in WordPress customizer?
- Uncaught TypeError [closed]
- Correct way to include extra styles & script files?
- How can I allow HTML in Gutenberg UI elements help text?
- UnitControl – Block has encountered an error
- Should I manually resolve WP Core File security issues or await a subsequent WP release?
- My code will not execute in wordpress, even though I’ve been told the code is fine
- Gutenberg – dynamically created element: how to set onChange?
- JSX SVG Icon with WordPress
- Can I just insert JavaScript by using ?
- Gutenberg Edit Block Inspector Controls and save
- JavaScript and Google PageSpeed + wp_enqueue_script
- How to integrate a different (JavaScript) editor in WordPress?
- Add Javascript/Html into a WordPress