Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
Is there a way to display multi-line string in Javascript?

I have a function which receives a single line string and displays it without a problem using an alert pop up from alertify JS but when its a multi-line string it gives an error saying Uncaught SyntaxError: Invalid or unexpected token . Below is my function:

<script>
function changes(changes) {

    alertify.confirm(changes,
        function () {
        }).setHeader('Document Changes');
}

The changes is the string am receiving and am displaying it in an alert box. Below is where am getting the changes from. I am getting this string from an object and passing it to my function

                {
                "render": function (data, type, full, meta) {
                    return '<button onclick="changes(\'' + full.changes + '\')" class="btn btn-info"><i class="fas fa-info-circle"></i> Changes</button>';
                }
            }

When i click this button it does not send the multi-line string to my function but when its a single line string it works without a problem

The sample text which brings the error is like below:

added footer

added heder

added content

Below is a fiddle which i have replicated the error Js Fiddle

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

if the problem was multi lines strings, you can use the back ticks ` to print the multi line strings in javascript

alert(`this is \n multi line \n string`)

and in your case would be:

alertify.confirm(`${changes}`,....
over 4 years ago · Santiago Trujillo Denunciar

0

Use the backticks, Luke.

let changes =`
This is a 
multiline
alert
message
`;

alert(changes);

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda