JSFiddle - React, Tailwind, and code Playground
HTML
<table id="tabelle">
<thead>
<tr>
<th>Name</th>
<th>Rasse</th>
</tr>
</thead>
<tbody></tbody>
</table>
CSS
table td {
padding: 5px 20px;
text-align: left;
}
JavaScript
var $table = document.getElementById("tabelle").getElementsByTagName('tbody')[0];
/********** KATZEN **********/
var Katze = function () {}
Katze.prototype.rasse = "Europäisch Kurzhaar";
Katze.prototype.setRasse = function (rasse) {
this.rasse = rasse;
}
// Katze Maunzi
var maunzi = new Katze();
console.log('maunzi:', maunzi);
var newrow = document.createElement('tr');
newrow.innerHTML = '<td>Maunzi</td><td>' + maunzi.rasse + '</td>';
$table.appendChild(newrow);
// Katze Maunzi neu
Katze.prototype.setRasse = function (rasse) {
this.rasse = 'neu: ' + rasse;
}
maunzi.setRasse('Hauskatze');
console.log('maunzi:', maunzi);
var newrow = document.createElement('tr');
newrow.innerHTML = '<td>Maunzi</td><td>' + maunzi.rasse + '</td>';
$table.appendChild(newrow);
/********** HUNDE **********/
var Hund = function () {
this.rasse = "Schäferhund";
this.setRasse = function (rasse) {
this.rasse = rasse;
}
}
// Hund Bello
var bello = new Hund();
console.log('bello:', bello);
var newrow = document.createElement('tr');
newrow.innerHTML = '<td>Bello</td><td>' + bello.rasse + '</td>';
$table.appendChild(newrow);
// Hund Bello neu
Hund.setRasse = function (rasse) {
this.rasse = 'neu: ' + rasse;
}
bello.setRasse('Mischling');
console.log('bello:', bello);
var newrow = document.createElement('tr');
newrow.innerHTML = '<td>Bello</td><td>' + bello.rasse + '</td>';
$table.appendChild(newrow);