Computerguy
Computerguy

Reputation: 13

Jquery css show div?

Ok this is my problem that no one can seem to answer. I have two javascripts in use. Once is for the popup I have and tells it to stay closed for 24hrs when closed. The other is to put a link some where on the page to display this popup until refreshed and kept hidden till the cookie expires. Now the div popup is set to display:none. The cookie tells it to be shown until the close button is pressed. No matter what I seem to rework in my javascript to tempoarly show the popup from a link, it will not show. Some how the cookie javascript is going to have to be modified and thus having to remove css:display:none on the popup div. I have no idea what to do.

This is the current code:


<script type="text/javascript"> 
$("#linkshow").click(function {
$("#window").show()
});        
</script>

<a href="#" id="linkshow">Submit a comment</a>
<div id="window">
...
<div>
<script type="text/javascript">
...cookie popup hide for 24hr on close
</script>

Note: I have already tried:

$(document).ready(function() {
   $("#linkshow").click(function(e) {
      e.preventDefault();
      $("#window").show();
   });
}); 

and...

$(document).ready(function() {
     $("#window").hide();

   $("#linkshow").live('click', function(e) {
      e.preventDefault();
      $("#window").show();
   });
}); ​

and...

$(function() {
        $("#linkshow").click(function() {
            $("#window").show()
        });        
    });

and...

<div id="window" style="display:none;">

to

<div id="window">

Then the other 24hr cookie javascript doesn't keep the popup hidden. I am assuming I need to take out the id="window" style="display:none; and some how advanced the javascript cookie at the bottom the code so it will hide when asked to be hidden for 24hr and show when needed to be shown on the current page until refresh but I am at blank on what to do.

Upvotes: 0

Views: 703

Answers (2)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

Your syntax is wrong, Try

$(document).ready(function() {
   $("#linkshow").click(function(e) {
      e.preventDefault();
      $("#window").show();
   });
}); 

Works for me: See jsFiddle

Upvotes: 2

Rory McCrossan
Rory McCrossan

Reputation: 337560

You need to wrap your code in a DOM ready handler, and you also missed the brackets following the function declaration. Try this:

<script type="text/javascript"> 
    $(function() {
        $("#linkshow").click(function() {
            $("#window").show()
        });        
    });
</script>

Upvotes: 0

Related Questions