Sergey Scopin
Sergey Scopin

Reputation: 2245

Prepending a first row to table with jQuery

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?

Upvotes: 0

Views: 236

Answers (2)

Blu
Blu

Reputation: 4056

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

Upvotes: 2

Salman Arshad
Salman Arshad

Reputation: 272106

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>\
";

Upvotes: 1

Related Questions