Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  141] [ 2]  / answers: 1 / hits: 51813  / 11 Years ago, fri, august 23, 2013, 12:00:00
var NewRow = document.createElement(<tr><td align='left' valign='top'  width='9%;'  ><img width='32px' height='32px' src='images/ + ProfilePic + '  /></td><td align='left' valign='Top' ><span class='MsgSpan'> + Msg + </span></td><td align='right' align='left' valign='top' style='color:Gray;' > + Date + </td></tr>);


I am getting an error:



InvalidCharacterError: String contains an invalid character


How can I fix this?


More From » javascript

 Answers
54

The string you pass to document.createElement is the type of the element, e.g. tr.



If you really want to assemble your HTML as a big string, I suppose you could write:



var newRow = document.createElement('tr');
newRow.innerHTML = <td align='left' valign='top' width='9%;' ><img width='32px' height='32px' src='images/ + ProfilePic + ' /></td><td align='left' valign='Top' ><span class='MsgSpan'> + Msg + </span></td><td align='right' align='left' valign='top' style='color:Gray;' > + Date + </td>;


but it's probably cleaner/faster/safer to use DOM manipulation for the whole thing.


[#76190] Thursday, August 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
havenbilliec

Total Points: 324
Total Questions: 106
Total Answers: 94

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;