Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
hii friends,


i implemented slidetoggle functions using jquery

here my issue is when i click first time it's not working.second time i click it's working.

i am using this code


C#
$("document").ready(function () {
      var active = false;
      if ($("#HiddenField1").val() == "block") {
          $("#FiltersliderDiv").css("display", "none");

      }
      if ($("#HiddenField1").val() == "none") {
          $("#FiltersliderDiv").css("display", "block");
          $("#Filters").css('background-color', '#0082AA');
          $("#MapAndChart").css('background-color', '#0082AA');
          $("#Report").css('background-color', '#0082AA');
      }
      $("#Filters").click(function () {

        if (active == false) {
              $("#FiltersliderDiv").slideDown("slow");
              $("#ReportsliderDiv").slideUp("slow");

              $("#MapAndChartsliderDiv").slideUp("slow");
              $("#MapAndChart").css('background-color', 'Gray');
              $("#Filters").css('background-color', '#0082AA');
              $("#Filters").css('fontcolor', '#333333');
              $("#Report").css('background-color', 'Gray');

              document.getElementById("MapAndChart").style.color = "black";
              document.getElementById("Report").style.color = "black";
              document.getElementById("Filters").style.color = "White";
              active = true;
          }
          else {
              $("#FiltersliderDiv").slideUp("slow");
              $("#Filters").css('background-color', 'Gray');
              document.getElementById("Filters").style.color = "black";

              active = false;
          }


      });
  });

  $("document").ready(function () {
      var active = false;
      if ($("#HiddenField2").val() == "block") {
          $("#MapAndChartsliderDiv").css("display", "none");
          $("#MapAndChart").css('background-color', 'Gray');
      }
      if ($("#HiddenField2").val() == "none") {
          $("#MapAndChartsliderDiv").css("display", "block");

      }

      $("#MapAndChart").click(function () {


          if (active == false) {
              $("#MapAndChartsliderDiv").slideDown("slow");
              $("#FiltersliderDiv").slideUp("slow");
              $("#ReportsliderDiv").slideUp("slow");

              $("#MapAndChart").css('background-color', '#0082AA');
              $("#Filters").css('background-color', 'Gray');
              $("#Report").css('background-color', 'Gray');

              document.getElementById("MapAndChart").style.color = "White";
              document.getElementById("Report").style.color = "black";
              document.getElementById("Filters").style.color = "black";
              active = true;
          }
          else {
              $("#MapAndChartsliderDiv").slideUp("slow");
              $("#MapAndChart").css('background-color', 'Gray');
              document.getElementById("MapAndChart").style.color = "black";
              active = false;
          }

      });
  });
  $("document").ready(function () {
      var active = false;
      if ($("#HiddenField3").val() == "block") {
          $("#ReportsliderDiv").css("display", "none");
          $("#Report").css('background-color', 'Gray');

      }
      if ($("#HiddenField3").val() == "none") {
          $("#ReportsliderDiv").css("display", "block");

      }

      $("#Report").click(function () {
          if (active == false) {
          $("#ReportsliderDiv").slideDown("slow");
          $("#FiltersliderDiv").slideUp("slow");
          $("#MapAndChartsliderDiv").slideUp("slow");

          $("#MapAndChart").css('background-color', 'Gray');
          $("#Filters").css('background-color', 'Gray');
          $("#Report").css('background-color', '#0082AA');

          document.getElementById("MapAndChart").style.color = "black";
          document.getElementById("Report").style.color = "White";
          document.getElementById("Filters").style.color = "black";
          active = true;

          }
      else {
          $("#ReportsliderDiv").slideUp("slow");
          $("#Report").css('background-color', 'Gray');
          document.getElementById("Report").style.color = "black";

          active = false;
          }
      });
  });



please share any idea to me.
Posted

1 solution

Please change your all click events is as below and after that test it.

C#
$("#Filters").off('click').on('click', function(){

  //your code here

  return false; //to prevent the browser actually following the links!

});
 
Share this answer
 
v2
Comments
krish2013 11-Mar-14 4:59am    
hii Sampth,
it's not working please share any code to me.
Sampath Lokuge 11-Mar-14 5:10am    
Did you check, are there any errors on JS file by using chrome dev tools ?
krish2013 11-Mar-14 5:45am    
hi sampath,
no errors are there
Sampath Lokuge 11-Mar-14 6:06am    
Can we test this on live (any url) ?
krish2013 11-Mar-14 6:12am    
no sampath can i share total code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900