jQuery: Using window url parameter

Let’s say we have passed a parameter to URL: www.mysite.com/?page=test

To collect the data form parameter we can use this function:

function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));

use of this code:



if (getUrlParameter('page') == 'test'){
// do something

Australian postcodes with Geolocation

Recently I needed Australian postcodes with Geolocation to work on a project. I have foked the list form randomecho; modified & converted to CSV & JS/JSON format. You can download or fork from here.

Select random element using jQuery

Everytime you refresh, it will select random element & show it’s class

Removing CSS file link dynamically

Here style.css is already exist on the top of the file.
I am using just one line jQuery code to remove the CSS.


Javascript: change div or span content

document.getElementById("myAnchor").innerHTML = "Shohag Bhuiyan";
document.getElementById("myAnchor").href = "http://www.shohagbhuiyan.com";
document.getElementById("myAnchor").target = "_blank";

Accessing variables from other functions without using global variables

var MyApp = {}; // Globally scoped object
function foo(){
MyApp.color = 'green';
function bar(){
alert(MyApp.color); // Alerts 'green'

JS: Hide Something

Simple jQuery Read More/Less Example

ref: Code-Tricks