Javascript Archive

  • This small but very handy piece of code… onclick="javascript:return confirm('Are you sure you want to delete this?')" For example: <input type="submit" name="button" value="Delete Page" onclick="javascript:return confirm('Are you sure you want...

    Javascript ‘Are You Sure?’ Message

    This small but very handy piece of code… onclick="javascript:return confirm('Are you sure you want to delete this?')" For example: <input type="submit" name="button" value="Delete Page" onclick="javascript:return confirm('Are you sure you want...

    Continue Reading...

  • Sometimes you need to change something depending on the browser size. Often this means that you’ll need to check for the browser being resized too… To do this you use:...

    window.onresize

    Sometimes you need to change something depending on the browser size. Often this means that you’ll need to check for the browser being resized too… To do this you use:...

    Continue Reading...

  • Ever had it where your stylesheet contains code that doesn’t validate with the W3C standards…. Yet there’s not an easy way round it? For example ‘opacity’….. This code adds an...

    Validating in-valid CSS

    Ever had it where your stylesheet contains code that doesn’t validate with the W3C standards…. Yet there’s not an easy way round it? For example ‘opacity’….. This code adds an...

    Continue Reading...

  • The getElementsByClassName() is already present in some modern browsers, but this code from Kevin Yank at Sitepoint just adds it for those browsers that don’t already have it…. function getElementsByClassName(className)...

    Create getElementsByClassName() function for use in IE

    The getElementsByClassName() is already present in some modern browsers, but this code from Kevin Yank at Sitepoint just adds it for those browsers that don’t already have it…. function getElementsByClassName(className)...

    Continue Reading...

  • Quick Reference guide of dot operators: .length // counts the number of items in an array .nodeName // reference the name of the node, i.e. p for p tag, etc....

    JavaScript Dot Operator List

    Quick Reference guide of dot operators: .length // counts the number of items in an array .nodeName // reference the name of the node, i.e. p for p tag, etc....

    Continue Reading...

  • Basic list of example code you can copy & paste… var myElement = document.getElementById("elementId"); var listItems = document.getElementsByTagName("li"); for (var i = 0, ii = listItems.length; i < ii; i++)...

    JavaScript Quick Syntax Check

    Basic list of example code you can copy & paste… var myElement = document.getElementById("elementId"); var listItems = document.getElementsByTagName("li"); for (var i = 0, ii = listItems.length; i < ii; i++)...

    Continue Reading...

  • The typical format for a ‘for loop’ to run through the list items in an array is as follows… var myArray = [1, 2, 3, 5, 8, 13, 21, 34];...

    Speeding Up ‘For Loops’

    The typical format for a ‘for loop’ to run through the list items in an array is as follows… var myArray = [1, 2, 3, 5, 8, 13, 21, 34];...

    Continue Reading...

  • To create an array in JavaScript is pretty straight forward, just declare the variable name equal to empty square brackets, like this: var rack = []; To add variables, you...

    Create a JavaScript Array

    To create an array in JavaScript is pretty straight forward, just declare the variable name equal to empty square brackets, like this: var rack = []; To add variables, you...

    Continue Reading...

  • In the words of Sitepoints Kevin Yank…. Your variable names can comprise almost any combination of letters and numbers, though no spaces are allowed. Most punctuation and symbols have special...

    JavaScript Accepted Variable Names

    In the words of Sitepoints Kevin Yank…. Your variable names can comprise almost any combination of letters and numbers, though no spaces are allowed. Most punctuation and symbols have special...

    Continue Reading...

  • One thing you need to be careful of, and has caught me out a few times when jumping from PHP to Javascript, is ‘new lines’…. In JavaScript a new line...

    Javascript & New Lines

    One thing you need to be careful of, and has caught me out a few times when jumping from PHP to Javascript, is ‘new lines’…. In JavaScript a new line...

    Continue Reading...

Page 1 of 212