jQuery SlideShow - Short and Sweet

    $('#slides img:gt(0)').hide();
        $('#slides :first-child').fadeOut().next('img').fadeIn(1000).end().appendTo('#slides');

Get the Base URL Javascript Function

function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));
    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);
        return baseLocalUrl

Get URL arguments using Javascript - $_GET Variables

if ( != "")
	var x =";")
	for (var i=0; i<x.length; i++)
		var y = x[i].split("=");
		alert("Key '" + y[0] + "' has the content '" + y[1]+"'")

Remove Newline from Text of Element / Convert \n to <br />

I was trying to write an if statement to perform some actions when a certain error message was present. I went round and round trying to figure out why the text of the element wouldn't match in my if statement. Turns out it was because there was a line break before the text which is considered content.

Tooltip Plugin - Cross Browser and Image Map Compatible

I tried several tooltip plugins for use with an image map. The only one that placed the tooltip where it should be placed when hover an area on the map was qTip

qTip is an advanced tooltip plugin for the ever popular jQuery JavaScript framework.

Built from the ground up to be user friendly, yet feature rich, qTip provides you with tonnes of features like rounded corners and speech bubble tips, and best of all... it's completely free under the MIT license!

Javascript Cookies Using jQuery Cookie Plugin

I chose to use the improved version of the jQuery Cookie Plugin with more functions as well as short/easy examples on how to use these functions.
(jQuery Cookie Project Page)

Ask For Confirmation When Leaving a Page

Ask for confirmation when leaving a page in javascript is useful when you have a multistep form or lengthy form that the user may expect to be saved. This code will execute whenever the page is about to be unloaded, to include clicking any links to a new page, using the forward/back buttons of the browser, and when using the address bar to go to a new site or page.

var warning = true;
window.onbeforeunload = function()
     if (warning) 
    return 'You have made changes on this page that you have not yet confirmed.

Prevent the Enter Key From Submitting a Form: javascript char codes (key codes)

This snippet will prevent the enter key being pressed from submitting a form or clicking the button that is in focus. Replace #foo with the id, class, or element.

Syndicate content