Discussion:
Show/hide div based on URL parameter
dikker
15 years ago
Permalink
Hi guys,

Am a beginner with Jquery and what i want is as follows.
I have a div that should be hidden on default, but when a certain URL
parameter is present, then the div is visible.

I am basing the following on this demo :
http://sandbox.ajaxcssblog.com/jquery/jquery.url/url-demo.htm

I have the following html
------------------------------------------------------------------------
<div id="display" style="display:hidden;">
<h2>header</h2>
<p>test text</p>
</div>
------------------------------------------------------------------------

And i have the following in the head
------------------------------------------------------------------------
<script type="text/javascript" id="demoscript">
$(function(){
$("#display").text($.url.param("loginstatus") || "... nothing yet");
});
</script>
------------------------------------------------------------------------

What i basically want is that when the URL parameter shows
index.html?showdiv=yes
then the div should be displayed.

So it would make sense to put an IF statement in the script as well, the
only problem is that i cannot or do not understand how i can modify the JS
script in such a way that it does just that.

I have tried many variations with IF and ELSE statements but nothing ever
seems to work as i am probably missing how to close tags properly etc.

Would anyone be willing to steer me in the right direction?
--
View this message in context: http://old.nabble.com/Show-hide-div-based-on-URL-parameter-tp27576002s27240p27576002.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.
Andrei Eftimie
15 years ago
Permalink
<script type="text/javascript" id="demoscript">
$(function(){
if (document.location.href.indexOf('showdiv=yes') > 0)
$("#display").show();
});
</script>
...
--
Andrei Eftimie
http://eftimie.com
+40 758 833 281

Punct
http://designpunct.ro
dikker
15 years ago
Permalink
Thank you Andrei!
Nice and simple, very well!
...
--
View this message in context: http://old.nabble.com/Show-hide-div-based-on-URL-parameter-tp27576002s27240p27620977.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.
Loading...