Frage

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?

War es hilfreich?

Lösung 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>\
";

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top