I want to display a div only if the user types in a query in the URL. I have the following code:
HTML
<div id="hidden" style="width:100%;height:20%;background-color:blue;display:none;">
Hidden Div Contents
</div>
JS
$(function() {
var params = {};
var ps = window.location.search.split(/\?|&/);
for (var i = 0; i < ps.length; i++) {
if (ps[i]) {
var p = ps[i].split(/=/);
params[p[0]] = p[1];
}
}
var divToShow = params.from;
$('#'+divToShow).show();
});
JSFiddle - http://jsfiddle.net/b48zL/
Link to see it works - http://jsfiddle.net/b48zL/show/?from=hidden
Problem
It appears to function correctly on the fiddle but on my server it renders the div with or without the query with the text from the script printed in the div.
ie, it looks as though I coded:
<div>$(function() { ... ...$('#'+divToShow).show();});</div>
Why?