Say I want to print html from inside a script tag.
A source like this
foo
$('element').html('<h1>TEXT TO INSERT</h1>');
or
$('element').text('TEXT TO INSERT');
From w3school's page on JavaScript output,
JavaScript can "display" data in different ways:
Writing into an alert box, using window.alert().
Writing into the HTML output using document.write().
Writing into an HTML element, using innerHTML.
Writing into the browser console, using console.log().
You can use document.write, however it's not a good practice, it may clear the entire page depends on when it's being executed.
You should use Element.innerHtml
like this:
<div>foo</div>
<span id="insertHere"></span>
<div>bar</div>
<script>
document.getElementById('insertHere').innerHTML = '<div>Print this after the script tag</div>';
</script>
l('output text example')
after once defining
l=console.log
seems fine to me for a quick hacksy JS debugging in the browser console.
Based on @Lil' Bits’s answer – thanks!