Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: Uncaught SyntaxError: Invalid or unexpected token

I am also using socket.io. There is an HTML table, and when a user clicks a button, my code is supposed to replace that table with a new one, however it gives the error message in the title.

Here is my code:
HTML:

<table>
                </tbody>
                    <tr>
                        <td class="1"></td>
                        <td class="2"></td>
                        <td class="3"></td>
                    </tr>
                    <tr>
                        <td class="4"></td>
                        <td class="5"></td>
                        <td class="6"></td>
                    </tr>
                    <tr>
                        <td class="7"></td>
                        <td class="8"></td>
                        <td class="9"></td>
                </tr>
                </tbody>
            </table>

JQuery script:

socket.on('resetGranted', function() {
        $('table').replaceWith('<table>    //says error is here
                </tbody>
                    <tr>
                        <td class="1"></td>
                        <td class="2"></td>
                        <td class="3"></td>
                    </tr>
                    <tr>
                        <td class="4"></td>
                        <td class="5"></td>
                        <td class="6"></td>
                    </tr>
                    <tr>
                        <td class="7"></td>
                        <td class="8"></td>
                        <td class="9"></td>
                </tr>
                </tbody>
            </table>');
    })

How do I fix this?

like image 476
J Duh Avatar asked Mar 26 '26 02:03

J Duh


1 Answers

Use backtick ` for multiline string

console.log(`
    multi
    line
    string
    here
`);
like image 171
Thum Choon Tat Avatar answered Mar 27 '26 14:03

Thum Choon Tat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!