javascript - string literal contains an unescaped line break ← (PHP, JavaScript)

I have an error in console

Uncaught SyntaxError: '' string literal contains an unescaped line break

'<ul>\n' +
'<?php for ($i = 1; $i < 31; $i++){
        echo '<li onclick="updateBasket('.$i.','+value['basketID'].')"><?= $i ?></li>';
    }
?>'+
'</ul>\n' +

Answer



Solution:

Try this. This will replace your PHP loop with the same thing but in JavaScript. Replace everything including the lines that open and close the <ul>.

// End previous concatenation.
'<ul>\n';
// Insert 30 list items.
for (let i = 0; i < 30; i++)
    tr += '<li onclick="updateBasket(' + i + ', ' + value['basketCount'] + ')">' + i + '</li>';
// Continue your concatenation as before.
tr +=
'</ul>\n' +

Source