i need using variable to create simple table "test" one cell ,can you help me ? my code: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script> var test; test+="<table>"; test+="<tr><td>First name:</td></tr>"; test+="</table>"; //alert (test); </script> </head> <body> </body> </html> Code (JavaScript):
You can do so by declaring var test = ''; test += '<table>'; test += '<tr><td>Test</td></tr>'; test += '</table>'; Code (JavaScript): Create a table in HTML <div id="table">...</div> HTML: Then insert it into by doing this (using jQuery) $('#table').html(test); Code (JavaScript):
1) why are you wasting a string on trying to use scripting to make markup. It's called the DOM, use it. 2) are you sure this is going to be tabular data? That looks suspiciously like it would be a label. If that IS a table element, would that be a TH? 3) what's the actual content and application you are going for with this? 4) you don know you generally shouldn't be trying to make render elements from inside HEAD, even via scripting (unless you delay it for domcontentready or onload), right? Not sure what you are trying to do, but I suspect that would be doing it all wrong. ... as would be throwing the fat bloated nonsense of jQuery-tardery at it and using a string to make DOM elements; it's ANOTHER of the reasons I think jQuery is halfwit bull since it actively encourages scripttards to do things we've been told for over a decade to stop doing; like using document.write or innerHTML