Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:34:20+00:00 2026-06-15T22:34:20+00:00

I want to toggle open and hide words when I toggle the panel. Here

  • 0

I want to toggle open and hide words when I toggle the panel.

Here is the code I used. it works only for hide but when I click next time it doesnt show open.

$(document).ready(function(){
        $(".flip1").click(function(){
            $(".panel1").slideToggle("slow");
       var val= 0;
       if(val==0){
        $('#word').html("hide").show();
        val=1;
       }else{
        $('#word').html("open").show();
        val=0;

       }
           // $(".info").hide();
        });
    });

help me to correct this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:34:22+00:00Added an answer on June 15, 2026 at 10:34 pm

    Move this line:

    var val= 0;
    

    Out of the click() callback.

    Where you have it it is a local variable within your click handler, and it gets set to 0 every time the handler is called. Move it outside the handler and it will get initialised to 0 once, and then updated within the click handler.

    Alternatively, get rid of that variable altogether and do something like this:

    $(document).ready(function(){
        $(".flip1").click(function(){
            $(".panel1").slideToggle("slow");
            $("#word").html(function(i,oldHtml) {
               return oldHtml==="hide"?"show":"hide";
            }).show();
        });
    });
    

    Demo: http://jsfiddle.net/9S5eq/

    EDIT: If you pass a callback to the .html() method, jQuery calls it for each element in the jQuery object, passing the index of the current element within the object and that element’s current html. It sets the html to whatever value you return. So in this case where there is only one element the index parameter isn’t actually needed at all, but you can’t leave it out because the current value is passed in the second parameter (so i is just a sort of placeholder).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(document).ready(function(){ $('#content1').hide(); $('a#open').click(function(){ $('#content1').show('slow'); }); $('a#close').click(function(){ $('#content1').hide('slow'); }) }); in this code of toogle
I have used the following code to get click outside to close working: Here
hello friends i want to use toggle on <li> when one <li> is open
I want to toggle element that id's pg when click link. header: <title>Example</title> <script
I want to toggle the ul when I click on group1 or group2 HTML
I am trying to have a panel slide open and close on click of
Here's the code I'm using $(document).ready(function(){ $('#slickbox').hide(); // toggles the slickbox on clicking the
I have found this code (jQuery): $('.toggle').click(function() { $('.container').eq($(this).index()).toggle('fast'); }); This is my HTML:
ok, So I have multiple divs(7) which I want to toggle for show hide.
I have the following code <p class=adv-toggle-buttons> <a id=button_open href=# style=display: none;>[+] Open advanced

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.