Hello Guys,
Hope you are doing great !
I’ve found some strange aspects which I never expected while creating HTML table with javascript. I’ve used multiline string to construct the table using “\”. I was completely unaware of the consequences. While accessing the table through DOM, number of children present in each row were being shown as more than what it is originally. I suppose the problem is changing innerHTML as a string which has HTML elements is resulting in wrong interpretation of “\” and white spaces by the browser.
Eg:
table = table + “<tr class=\”note\”>\
<td>”+res.rows.item(i).id + “</td>\
<td>”+res.rows.item(i).title + “</td>\
<td>”+pretext.substr(0,20)+ “…</td>\
</tr>”;
Here each row has 3 columns but in reality, accessing the children of
element will show the length as 6 i.e., threeand three “\”.
Conclusion is just be cautious while using “\” and updating innerHTML with HTML elements.