0

I need to put jquery-cookie for function showHide(shID) do anyone know how to do that ? I got a onclick button to show more content , using function showHide(shID) but I just need to hide for once .So is it possible to add jquery-cookie for it ?how can I do that ? [https://github.com/carhartl/jquery-cookie#readme][1]

here my code:function showHide(shID)

<script language="javascript" type="text/javascript">
function showHide(shID) {
   if (document.getElementById(shID)) {
      if (document.getElementById(shID+'-show').style.display != 'none') {
         document.getElementById(shID+'-show').style.display = 'none';
         document.getElementById(shID).style.display = 'block';
      }
      else {
         document.getElementById(shID+'-show').style.display = 'inline';
         document.getElementById(shID).style.display = 'none';
      }
   }
}
</script>

please , I need someone to guide me or let me know how to do that .Thanks in advance !

lucas
  • 67
  • 1
  • 2
  • 11

2 Answers2

0

Yes it's possible using cookie for use cookie you must have to include cookie file and jquery file. I give you example.

if($.cookie("example")=='1') {
    //get cookie and your hide code here.
} else {
    //set cookie
    $.cookie("example", "1");
}
Sunny
  • 432
  • 3
  • 8
  • Hi Sunny ! good to see u again ! and thanks again for your help .. is the code wrote like this ? sorry I am new in javascript http://jsfiddle.net/Garfrey/5xf72j4m/ – lucas Jan 30 '15 at 04:58
  • can you put your full code then i can help you better. – Sunny Jan 30 '15 at 05:10
  • check this i have done cookie code working. http://jsfiddle.net/sunnyept/xpv8nood/ – Sunny Jan 30 '15 at 07:33
  • Sunny , can these cookie code working on the show content ?means when people click on "Read more" ,then hidden content will show out ,and the cookie will effect hide function will only use once . http://jsfiddle.net/Garfrey/5xf72j4m/8/ – lucas Jan 30 '15 at 07:59
  • Yes, It will work but you have to code for your requirement. I have just done code for set cookie and get cookie. – Sunny Jan 30 '15 at 09:01
  • Thanks Sunny ! I will try hard to figure out how to code the requirement . If you are okay , I wish to get full code with this too , cause I have no javascript base not sure how to do . – lucas Jan 30 '15 at 10:01
0

Here is an answer ,solved by Ionica Bizau https://stackoverflow.com/users/1420197/ionic%C4%83-biz%C4%83u

function showHide(setCookie) {
    var shID = $(this).data("showhide")
      , $shEl = $("#" + shID)
      , $showHide = $("#" + shID + '-show')
      ;

    if ($shEl.is(":hidden")) {
        if (setCookie !== false) {
            jQuery.cookie("showhide-" + shID, 1);
        }
        $showHide.hide();
        $shEl.show();
    } else {
        if (setCookie !== false) {
            jQuery.cookie("showhide-" + shID, 0);
        }
        $showHide.show();
        $shEl.hide();
    }
}

jQuery(document).ready(function () {
    $("#example-show").on("click", showHide);
    if (jQuery.cookie("showhide-" + "example") == '1') {
        showHide.call($("#example-show").get(0), false);
    }
});

JQuery Cookie not function

Community
  • 1
  • 1
lucas
  • 67
  • 1
  • 2
  • 11