Thursday, September 11, 2014

jQuery log messages into the console

When debugging jQuery or JavaScript code, alerts are simple ways to output messages or data to see how the code is working and if certain code is being run etc. However there are times where the presence of an alert is not ideal and can break the flow of the code (for example if you are debugging page scroll, the alert stops the scrolling).

That is where console logging can be of assistance. Modern web browsers all have a developer tools menu built-in out of box (generally available by pressing F12). This menu will have a console option which commonly displays JavaScript information and also allows you to interact with the page via command line. There are four different options for manually outputing messages to the console:
These then get output as the following:

No comments:

Post a Comment