Javascript change class of Element using cookies
What I want to do is have an Layer Div (#introDiv) be visible for first visit, set a cookie so next and subsequent visits that layer will be hidden. CSS has .hide {display:none;}
I have used the method in [link] to set the cookies and that works fine. I have tried everything I can to try get the layer to hide but haven't been able to figure it out. In my html I have this: :: Code :: <script type="text/javascript">
// name, value, expires, path, domain, secure if ( Get_Cookie( 'homevisit' ) )changeClass(); Set_Cookie( 'homevisit', 'hide', '7', '/', '', '' ); </script> In script file: :: Code :: function changeClass(){
document.getElementById("introDiv").setAttribute("class","hide");} This gives an error: document.getElementById("introDiv")is null The cookie gets set but the div isn't hidden on refresh. Any help in getting this to work would be great thanks!!!! Back to top |
|||||
can't say except that getElementById is for ids, not classes. Given you're calling your function something class... it's hard to know if that's what you mean, or if your html is right.
Usually when you get that error it's because the css id isn't located in the running page code. Back to top |
|||||
It works if I put a button with an onclick="change()" on the page then click the button. Seems like it needs an event trigger to active it, it wont active just from if ( Get_Cookie( 'homevisit' ) )changeClass();
Back to top |
|||||
Found
I found a script that does this. If any one is interested it is at:
scriptden.blogspot.com/2009/07/show-div-once-day-using-javascript.html Back to top |
|||||
All times are GMT - 8 Hours
|