Hi I am trying to create a variable in jquery that contains a table for outputting in different areas of a website. But it is giving me an error, and I do not understand why. He
Syntax error due to wrongly assigned string.
concatenate the lines
var copy = "<table width='750' border='0' cellspacing='0' cellpadding='0'>"
+ "<tr>";
....
You haven't handled the line returns in your string. Because of this, javascript assumes that the end of each line is the end of a statement. Clearly each line is not a valid statement. Concatenate your string like so:
var "multi-"+
"line "+
"string";
Or you can use this tool http://www.accessify.com/tools-and-wizards/developer-tools/html-javascript-convertor/
It works fine :)
When I have complex html this is what I do. I put the html in an enclosing DIV
and get the html content
var copy = $('#mycomplexhtml').html(); //gets the content I placed in an hidden div
<!-- I normally place this at the bottom-most part of the page -->
<div id="mycomplexhtml" style="display:none">
<table width='750' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td>Tarifa valida desde:</td>
<td>Tarifa valida hasta:</td>
<td>Tarifa MXN</td>
<td>Tarifa USD</td>
</tr>
...
</table>
</div>
You could concatenate strings like it was suggested. Or another way is to escape new line characters with back slash:
var html = "<table> \
<tr>....</tr> \
</table>";