Question

I have a table in my code:

<table class="mainTable">
</table>

I want to prepend a head row to it.

var filter_all_head_row="
            <tr>\
                <th>smth</th>\
                                ...
                    <th>smth</th>\
                        </tr>
";

I'm trying to do it in onload of my page with this code:

$("table.mainTable").prepend(filter_all_head_row);

By the console says:

Uncaught SyntaxError: Unexpected token ILLEGAL

Solutions?

Was it helpful?

Solution 2

You are missing at least two \ in your string literal:

var filter_all_head_row="
    <tr>\
        <th>smth</th>\
        <th>smth</th>\
    </tr>
";

Should be:

var filter_all_head_row = "\
  <tr>\
    <th>smth</th>\
    <th>smth</th>\
  </tr>\
";

OTHER TIPS

Try this solution

var filter_all_head_row = '<tr>\
   <th>smth</th>\
   <th>smth</th>\
 </tr>';

you wrote like this

var filter_all_head_row = '
......

It should be like this

var filter_all_head_row = '\
......

Because every time you want to go next line you have to put this \. Also recommended that use some tool like Adobe Dreamviewer etc they will show this type of errors during writing of you code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top