php - How to hide div serverside by reading cookie -


I am using a tutorial from here:

This is the script I use:

  & lt; Script type = "text / javascript" language = "javascript" & gt; $ (Function () {// SETUP: // When the notification banner is clicked: $ ('#setup') Click (function () {$ ('# intro'). CSS ("Display", " No. "); $ .cookie ('intro', 'collapsed');}); // cookies // info banner state var intro = $ .cookie ('intro'); // Read the cookies if (intro = = 'Collapsed') {$ ('# Intro'). CSS ("display", "none");};}); & Lt; / Script & gt;  

Hides the following div as cookie:

  & lt; Div class = "feedback focus" id = "intro" & gt; Text goes here & lt; An id = "setup" href = "#" & gt; OK, I get it, please do it & lt; / A & gt; & Lt; / Div & gt;  

Everything works great but when the page loads, the split is shown for the second part. I believe that according to cookie information there is a solution to present two separate pieces of markup server I do not know how to go about this.

On page load, you can check the cookies using php, and then add a hidden class . Some & lt; Div class = "& lt;? = $ _COOKIE ['intro'] == 'collapsed'? 'Hidden': '' ?? & gt; & gt;

Edit :

Then in CSS, you can add something like Hide {display: none;} and use jQuery to add or remove that class.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -