You are trying to slideUp
an element (#cookies
) that doesn't appear to be in your HTML snippet you posted. Are you sure it's there?
If you want to show the message only once per IP you can store it in a cookie as explained here.
You can get an IP through JavaScript like this.
Update
"Can it be because my head and navigation(where the message is part from) are both separate php files that I include into index.php?"
- No, the files get 'merged' together before they are served to the client / browser.
You are trying to execute your script before jQuery is loaded. If you check your console you see this error Uncaught ReferenceError: $ is not defined
. jQuery defines $
as a shortcut to jQuery and because it isn't loaded yet it's still not defined and causes your script to error.
Put your script below the jQuery include at the bottom of the page. It's always good practice to put all the scripts at the bottom of your page (like the Google Analytics snippet) just before you close the body
-tag.
This makes sure that your HTML and CSS renders and doesn't get blocked by any JavaScript.
You might wrap your script inside a ready
handler, to make sure it doesn't get execute before the whole page is ready, like this:
$(document).ready(function() {
$("#hide").click(function() {
$("#cookies").slideUp(1000);
}); // don't forget the semicolon here
$("#show").click(function() {
$("#cookies").slideDown(1000);
}); // don't forget the semicolon here
});
Also don't forget to open the body
after you close the head
and close the body
and html
tags at the bottom of your page.
You might also want to take a look at the HTML5 Boilerplate for more best practices.