Steve Turley
Steve Turley

Reputation: 1

How do I make a div show if variable exist in url?

On login page when a customer wants to purchase wifi service they click on a link http://siteurl/terms.html?premium=show. I need to have the terms page display a hidden division if premium exist and is equal to show without using php.

Upvotes: 0

Views: 113

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82241

You can use .toggle(flag) with true/false for show/hide of the selected element:

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

$('hiddendivselector').toggle(getParameterByName('premium')=="show")

Function getparameter refered from

Upvotes: 1

Related Questions