Is there a way to write to the window line by line?

Started by ubacher, June 15, 2017, 10:01:04 PM

Previous topic - Next topic

ubacher

During debugging (at least) it would be convenient to write log messages to the window
(rather than to the console with console.log)
Using something like
document.getElementById("info").innerHTML = 'hello world';
only lets me write one time, the next time I use this it overwrites. I there a way to "append"?

I also tried something like:
mydiv.insertAdjacentHTML('afterend', '<p>'+sometext+'</p>');
after declaring <div id="mydiv"></div>in the body.

Still, I wonder if there is an easier way.


(Of course I could keep the text to be written in memory and append to it.)

thrinn

Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

document.getElementById("info").innerHTML

This is plain DOM programming. Boring. Long-winded. I recommend you use jQuery instead:

$('#info').text('bla');

Both statements set the content of the HTML tag.
There are several methods in jQuery to append. But the simplest way is to just keep your text in a string:

var text = 'Hello';
$('#info').text(text);

Add to the string and update the HTML tag again:

text += ' World!';
$('#info').text(text);

Or you can do this

$('#info').text( $('#info').text() + ' more text' );

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook