1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Varible and Table

Discussion in 'JavaScript' started by ssimon171078, Apr 22, 2015.

  1. #1
    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):
     
    ssimon171078, Apr 22, 2015 IP
  2. rolodex

    rolodex Well-Known Member

    Messages:
    364
    Likes Received:
    37
    Best Answers:
    5
    Trophy Points:
    175
    #2
    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):
     
    rolodex, Apr 24, 2015 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    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
     
    deathshadow, Apr 27, 2015 IP