I have an external file that creates a table using jQuery. I am trying to set the first column to be a different width to the other columns. I would prefer to add something to it that I can use in css to make future edits easier. I am struggling to get the syntax correct. A couple of my attempts are shown in code comments but I have tried others and failed with them too.
var $table = $('<table>');
$table.append()
// thead
.append('<thead>').children('thead')
.append('<tr />').children('tr').append('<th></th><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th>');
//tbody
var $tbody = $table.append('<tbody />').children('tbody');
// add row
$tbody.append('<tr />').children('tr:last')
//.append("<th class="dynamicTable-rowHead">name</td>") -console gives Uncaught SyntaxError: missing ) after argument list
//.append("<th>name</th>").setAttribute('width', '10%') //setAttribute is not a function
.append("<th>name</td>") //this works but cannot define a width in css without it affecting all table columns
.append("<td>val</td>")
.append("<td>val</td>")
.append("<td>val</td>")
.append("<td>val</td>")
.append("<td>val</td>")
.append("<td>val</td>")
.append("<td>val</td>");
// add table to dom
$table.appendTo('#dynamicTable');
<th>appendstable tbody th { width: 10%; }append()thenchildren()to select the element you just created can be negated by just usingappendTo(). Eg.var $tbody = $('<tbody />').appendTo($table);