0

My string javascript like this :

 <script>
 ...
     res += '<td class="${photo == photoMap[i].name ? 'success' : ''} image" id="thumb-view-'+i+'" \
                data-toggle="modal"  \
                data-target="#modal-option-'+i+'" \
                data-photo='${JSON.stringify(photoMap[i])}' \
                data-main_photo="'+photo+'" \
            > \
                <img src="/img/thumbs/'+photoMap[i].name+'" alt="${photoMap[i].alt ? photoMap[i].alt : ''}"> \
                ${photo == photoMap[i].name ? '<div class="box-check"><span class="fa fa-check"></span></div>' : ''} \
            </td>';
...
</script>

If the code executed, on the console exist error like this :

Uncaught SyntaxError: Unexpected identifier

It seems that the writing of the code is still not correct

If I observe, an error occurs in this section

res += '<td class="${photo == photoMap[i].name ? 'success' : ''} image" id="thumb-view-'+i+'" \

and

${photo == photoMap[i].name ? '<div class="box-check"><span class="fa fa-check"></span></div>' : ''} \

How can I solve it?

10
  • + success +, I think you forgot to concatenate it Commented Jun 21, 2017 at 2:03
  • @Swellar, success is string. No variable Commented Jun 21, 2017 at 2:04
  • Then I think the problem is you "cut" the string by using ', thus the compiler thought that success is not part of the string Commented Jun 21, 2017 at 2:06
  • They are correct. You need to escape the quotes for success and also the empty string following it Commented Jun 21, 2017 at 2:08
  • @Swellar, So what is the right solution? Commented Jun 21, 2017 at 2:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.