SyntaxError: unescaped line break in string literal

.

I’m getting the following console error when trying to execute the code below:

SyntaxError: '' string literal contains an unescaped line break

Despite checking my syntax several times, I haven’t been able to fix the error. Please take a look at the code and let me know if you notice something.

$('#nouveau').click(function(){
    $('#action').html('<?php echo preg_replace('/\s\s+/', '', $langs->trans("Delete") ); ?>');
    $('.titre_ecv').html('<?php echo addslashes(trim(preg_replace('/\s\s+/', '', $langs->trans("ecv_nouveau_formation")))); ?>');
    $('.nouveau').show();
    $('#valider').show();
    $id=$('#tr_formations tr').length+1; 
    $('#tr_formations').append('<tr><td><input name="action" type="hidden" value="create"><input type="text" name="formations['+$id+'][etablissement]" autocomplete="off" style="width:95%" /></td> <td style="width:10%;"> <select class="niveau flat" id="niveau" name="formations['+$id+'][niveau]" ><option value="0" ></option><option value="Qualifiant"  ><?php echo preg_replace('/\s\s+/', '', $langs->trans("Qualifiant") ); ?></option><option value="Bac" >Bac </option> <option value="Bac+1" >Bac+1 </option><option value="Bac+2" >Bac+2 </option><option value="Bac+3" >Bac+3 </option><option value="Bac+4" >Bac+4 </option><option value="Bac+5" >Bac+5 </option><option value="Master_specialisé" ><?php echo preg_replace('/\s\s+/', '', $langs->trans("Master_specialisé") ); ?> </option><option value="Master_recherche" ><?php echo preg_replace('/\s\s+/', '', $langs->trans("Master_recherche") ); ?> </option> <option value="Doctorat" >Doctorat </option></select> </td> <td ><input type="text"  name="formations['+$id+'][intitule]" autocomplete="off" style="width:95%" /></td> <td><input type="text"  name="formations['+$id+'][filiere]" autocomplete="off" style="width:95%" /></td><td style="width:8%;"><input type="text" name="formations['+$id+'][debut]" class="datepicker debut" value="<?php echo date('d/m/Y') ?>" onchange="MinDate(this);" autocomplete="off" /></td> <td style="width:8%;"><input type="text" name="formations['+$id+'][fin]" value="<?php echo date('d/m/Y') ?>" class="datepicker fin" onchange="MaxDate(this);" autocomplete="off" /><div align="center"><label><input type="checkbox" name="experiences['+$id+'][no_jours]" onchange="no_jourss(this);"> <b class="nos_jour"><?php echo trim(preg_replace('/\s\s+/', '', $langs->trans("ecv_no_jours") )); ?></b></label></div> </td><td align="center"><img src="<?php echo DOL_MAIN_URL_ROOT.'/theme/md/img/delete.png' ?>" class="img_delete" onclick="delete_tr(this);"></td></tr>');
    $( ".datepicker" ).datepicker({
        dateFormat: 'dd/mm/yy'
    });
    $(".niveau").select2()
});

The error is caused by unescaped line breaks within the string literals in the code. To fix it, you can escape the line breaks using backslashes (\). Here’s the corrected code:

$('#nouveau').click(function(){
    $('#action').html('<?php echo preg_replace(\'/\\s\\s+\', \'\', $langs->trans("Delete") ); ?>');
    $('.titre_ecv').html('<?php echo addslashes(trim(preg_replace(\'/\\s\\s+\', \'\', $langs->trans("ecv_nouveau_formation")))); ?>');
    $('.nouveau').show();
    $('#valider').show();
    $id=$('#tr_formations tr').length+1; 
    $('#tr_formations').append('<tr><td><input name="action" type="hidden" value="create"><input type="text" name="formations['+$id+'][etablissement]" autocomplete="off" style="width:95%" /></td> <td style="width:10%;"> <select class="niveau flat" id="niveau" name="formations['+$id+'][niveau]" ><option value="0" ></option><option value="Qualifiant"  ><?php echo preg_replace(\'/\\s\\s+\', \'\', $langs->trans("Qualifiant") ); ?></option><option value="Bac" >Bac </option> <option value="Bac+1" >Bac+1 </option><option value="Bac+2" >Bac+2 </option><option value="Bac+3" >Bac+3 </option><option value="Bac+4" >Bac+4 </option><option value="Bac+5" >Bac+5 </option><option value="Master_specialisé" ><?php echo preg_replace(\'/\\s\\s+\', \'\', $langs->trans("Master_specialisé") ); ?> </option><option value="Master_recherche" ><?php echo preg_replace(\'/\\s\\s+\', \'\', $langs->trans("Master_recherche") ); ?> </option> <option value="Doctorat" >Doctorat </option></select> </td> <td ><input type="text"  name="formations['+$id+'][intitule]" autocomplete="off" style="width:95%" /></td> <td><input type="text"  name="formations['+$id+'][filiere]" autocomplete="off" style="width:95%" /></td><td style="width:8%;"><input type="text" name="formations['+$id+'][debut]" class="datepicker debut" value="<?php echo date(\'d/m/Y\') ?>" onchange="MinDate(this);" autocomplete="off" /></td> <td style="width:8%;"><input type="text" name="formations['+$id+'][fin]" value="<?php echo date(\'d/m/Y\') ?>" class="datepicker fin" onchange="MaxDate(this);" autocomplete="off" /><div align="center"><label><input type="checkbox" name="experiences['+$id+'][no_jours]" onchange="no_jourss(this);"> <b class="nos_jour"><?php echo trim(preg_replace(\'/\\s\\s+\', \'\', $langs->trans("ecv_no_jours") )); ?></b></label></div> </td><td align="center"><img src="<?php echo DOL_MAIN_URL_ROOT.\'/theme/md/img/delete.png\' ?>" class="img_delete" onclick="delete_tr(this);"></td></tr>');
    $( ".datepicker" ).datepicker({
        dateFormat: \'dd/mm/yy\'
    });
    $(".niveau").select2()
});