How would I print something to the result screen in JsFiddle from my JavaScript. I can't use document.write()
, it doesn't allow it, neither print
.
What should I use?
How would I print something to the result screen in JsFiddle from my JavaScript. I can't use document.write()
, it doesn't allow it, neither print
.
What should I use?
To be able to see output from console.log()
in JSFiddle, go to External Resources on the left-side panel and add the following link for Firebug:
I have a template for this purpose; here is the code I use:
<pre id="output"></pre>
function out()
{
var args = Array.prototype.slice.call(arguments, 0);
document.getElementById('output').innerHTML += args.join(" ") + "\n";
}
out("Hello world!");
out("Your lottery numbers are:", Math.random(), 999, Math.PI);
out("Today is", new Date());
innerText
instead of innerHTML
and send the log to the original console as well:function newLog(oldLog) { return function() { var args = Array.prototype.slice.call(arguments, 0); document.getElementById('console-log').innerText += args.join(" ") + "\n"; oldLog.apply(this, args) } } console.log = newLog(console.log) console.error = newLog(console.error)
JSFiddle example –
Vilhelmina document.getElementById('element').innerHTML += [stuff here] + "<br/>";
if you want to have multiple lines and add information to the page, instead of just replacing the old information. –
Anastatius Might not do what you do, but you can type
console.log(string)
And it will print the string into the console of your browser. In chrome push CTRL + SHIFT + J to open the console.
CTRL
+SHIFT
+K
if you want the console to be docked at the bottom of the page, instead of floating around in a separate window. –
Anastatius You can do this --->
http://jsfiddle.net/chY5y/
$('body').append(yourVariable);
Now jsfiddle can do it from the scratch. Just go to Javascrpt --> Frameworks & extensions --> Jquery(edge) and check Firebug lite checkbox
document.body.innerHTML = "Your data";
document.body.innerHTML += "Your data" + "<br/>"; document.body.innerHTML += "Even more data" + "<br/>";
–
Ancelin With ES6 tricks could be
function say(...args)
{
document.querySelector('#out').innerHTML += args.join("</br>");
}
say("hi","john");
Add only
<span id="out"></span>
in HTML
Here's one alternative: http://jsfiddle.net/skibulk/erh7m9og/1/
document.write = function (str) {
document.body.insertAdjacentHTML("beforeend", str);
}
document.write("¡hola mundo");
Just to add something that might be useful to some folks....
If you add the debugger console as shown above, you can access the scope by executing this:
scope = angular.element(document.querySelector('[ng-controller=MyCtrl]')).scope();
I find inspecting the scope directly easier than console.log, alert(), etc.
If you're using JSfiddle, you can use this library: https://github.com/IonicaBizau/console.js
Add a rawgit of the lib to your jsfiddle resources:
https://cdn.rawgit.com/IonicaBizau/console.js/0ee8fcc4ea802247c5a7a8e3c6530ede8ade308b/lib/console.min.js
Then you can just add this in the HTML:
<pre class="console"></pre>
Initialize the console in your JS:
ConsoleJS.init({selector: "pre.console"});
Usage Example: See it on jsfiddle
ConsoleJS.init({selector: "pre.console"});
let b;
console.log('hello world');
console.log([{'a':10,'b':44}]);
console.log(typeof [1,2,3,4]);
console.log(50 +67);
console.log(b);
I'm not sure why this isn't an answer or upvoted in the comment by Rubén
Nowadays jsfiddle allows the use of document.write() – Rubén Jul 16, 2018 at 19:05
Adding it as an answer for anyone looking.
Use the alert()
function:
alert(variable name);
alert("Hello World");
© 2022 - 2025 — McMap. All rights reserved.
console.log()
accepts arguments differently than your custom function). – Anastatius