Javascript

JS sections

*OnLoad

  • *Hide default HTML element, print JS variation.
  • *Only available to JS browsers

*DocReady

  • *Hide default HTML element, print JS variation.
  • *Only available to JS browsers

Encode HTML Characters

function htmlDecode(value){
    return $('<div/>').html(value).text();
}

Detect browser and OS.

Debugging

Using an error console, such as Firebug, you can add alert messages to functions to test if the script is running or if the particular function is firing. You can also use 'console.log' instead of 'alert', if you are debugging on a live site, as console.log only displays in the code.

console.log('Testing console');

Check if console is available

if ( window.console && window.console.log ) {
  // console is available
}

Basic setup

$( '#someButton' ).click ( function () {
  console.log ( '#someButton was clicked' );
  // do something
} );

Have some fun with it

alert(hasNinjas)
console.log(hasNinjas)

Resources

318 reads • Last Modified: Monday, August 1, 2016