Christian Fazzini
Christian Fazzini

Reputation: 19723

Is there a better way to log?

Whats the simplest / most efficient way to log a Javascript / jQuery output?

At the moment, I am using something like alert('foobar'); blocks in my code.

Upvotes: 0

Views: 258

Answers (4)

Tim Down
Tim Down

Reputation: 324567

You could use log4javascript (disclosure: I wrote it), which works in all major browsers, has a nice logging console with search and filtering and can also be used to send log messages to the server.

Upvotes: 0

E-man
E-man

Reputation: 451

Absolute simplest, use Firebug Lite.

Include the following code at the top of the <head> of your page:

<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>

That's it! It will bootstrap a logging console in your browser window, no matter which (modern) browser you're working with.

The Firebug console API can be found at the Firebug wiki.

There are a few other options for logging in JavaScript, but if you just want something simple that works... Firebug Lite is the best option.

Upvotes: 1

Craig M
Craig M

Reputation: 5628

console.log is better if the browser supports it.

if (window.console)
    console.log('foobar');

Upvotes: 3

Alex Wayne
Alex Wayne

Reputation: 187024

console.log('foobar');

Then check your JS console.

enter image description here

Upvotes: 7

Related Questions