Using jQuery and JavaScript to create rows and cells in an HTML table -


i've been browsing around google , stack overflow find answer, i'd direct answer question, post.

so, i'm new javascript , jquery, pardon ridiculousness haha.

$(document).ready(function(){    getgridsize();  });   function getgridsize() {   sizewidth = parseint(prompt("width?"));   sizeheight = parseint(prompt("height?"));   fillgrid(sizewidth, sizeheight); }  function fillgrid(width, height) {   (i = 0; < height; i++) {     $('table').append("<tr></tr>");     (j = 0; j < width; j++) {       $('tr').append("<td><div></div></td>")     };   }; } 

the above have in .js file currently. i'm using skeleton html file empty <table> </table> in body.

what i'm trying create "width" , "height" of table , fill in <div> in each cell. have css file change <div> files small squares black borders.

i saw tutorial helping develop create slider script jquery , js. code reminded me of class element in ruby using $(document).ready(function() block initialize.

my initial attempt @ project emulation of saw , i've experienced ruby. however, didn't turn out expected , i'd feedback on i've written far.

anyways, constructive criticism welcome. ok think of jquery ready block similar function initialize method in ruby? no-no's see here should avoid in future? helpful nudges in right direction please? :)

edit: think i've caught error , creations. edit once testing out.

edit2: ok, other attempt didn't work out. :( still seeking help

you should change function fillgrid this.

function fillgrid(width, height) {     (i = 0; < height; i++) {        var tr= $("<tr>");       (j = 0; j < width; j++) {         tr.append("<td><div>test</div></td>");       };       var table = $("<table>");       table.append(tr);       $(document.body).append(table);     };   } 

check plunker here.

note: have added sample text test can see table.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -