Search code examples
javascriptjquerycookiesshow-hidejquery-cookie

function showHide(shID) with jquery-cookie


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 !


Solution

  • 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