JSFiddle - React, Tailwind, and code Playground
by Andy Bulka
HTML
hi there
this is a test
of <b>things</b> in this world. <a href="javascript:hi()" hi>add</a>
<div id="out"></div>
JavaScript
/*
Append text to a html page
Javascript that writes to the document overwrites the body so you need to add text elements with javascript, and avoid document.write() - unless you have no static body text.
*/
// http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11430
function appendText(node, txt) {
node.appendChild(document.createTextNode(txt));
}
function appendElement(node, tag, id, htm) {
var ne = document.createElement(tag);
if (id) ne.id = id;
if (htm) ne.innerHTML = htm;
node.appendChild(ne);
}
// Andy
function MSG(divname, s) {
var crlf = true;
appendText(document.getElementById(divname), s);
if (crlf) appendElement(document.getElementById(divname), 'div', '', '');
}
function hello() {
//document.write('hello andy<br>');
MSG('out', 'hello andy');
MSG('out', 'hello andy again');
}
function hi() {
MSG('out', 'today is fine.');
}
hi();hi();