tags:

views:

25

answers:

2

I have a url format http://www.xyz.com/DisplayPost.php?postid=200

On the page, I have a div called div1 which gets it data from Google Adsense (script).

Here's what I want to do:

Start by hiding the div. Then I want to detect if the url does not have "postid=250" in it and display the div.

How can I do it using jQuery. What css attribute to use to open the page by hiding the div and then displaying it based on the condition

Want to know the right way to do it.

A: 

You can use a regex to search for that string (no jquery necessary) and then you can use div1.css('display','none'); (assuming that div1 has already been variableized)

SapphireSun
A: 

Use this code:

$(function(){
// hide the div initially
$("#div1").hide();

// Check to see if there is 250 in the url
var postID = getParameterByName('postid');

if (postID != 250)
{
  $("#div1").show();
}

});

// Javascript function to get query string value
function getParameterByName(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
Sarfraz