Separate single quote in String JS

2

I have a string like this:

var cadena = '<form name="name" th:action=" 'ERROR' ">';

I have some single quotes within the string and that is what limits the start and the end, how can I do to include the escape characters as part of the chain?

Greetings.

    
asked by Eduardo 04.06.2018 в 13:47
source

2 answers

8

To escape your single quotes you will have to escape with \ . Staying in the following way:

var cadena = '\'tu contenido\'';
    
answered by 04.06.2018 / 13:53
source
1

You can use the template strings to include the single quotes, in addition to having other features such as text strings of more than one line, they are used with the back tips or inverted tilde ', I leave a link so you can learn more about it < a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Referencia/template_strings"> link

    var cadena = ''''
    
answered by 04.06.2018 в 15:46