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

  • SEARCH
  • Home
  • 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 6895361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:53:56+00:00 2026-05-27T06:53:56+00:00

How can I get the label to toggle show/hide? Below is my code and

  • 0

How can I get the label to toggle show/hide? Below is my code and currently it is also displaying show. I would like it to toggle from show to hide and from hide back to show. when show is displayed the div will be hidden but when show is clicked the label will switch to hide and the div will be displayed and when hide is clicked the label will go back to show and the div will be hidden

  <html>
 <head>
<title>jQuery test page</title>
<script type="text/javascript" src="../scripts/jquery-1.4.2.js"></script>

<script type="text/javascript">
$(document).ready(function() {
$("#clickMe").click(function() {
 $("#textBox").toggle();
});
});
</script>
</head>
<body>
<label id="clickMe">Show</label>
<br />
<div id="textBox" style="display: none">This text will be toggled</div>
</body>
</html>
  • 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-05-27T06:53:56+00:00Added an answer on May 27, 2026 at 6:53 am

    If I read your question right, then I think the following would work:

    $('#clickMe').toggle(
                function(){
                    $('#textBox').show();
                    $('#clickMe').text('hide');
                },
                function(){
                    $('#textBox').hide();
                    $('#clickMe').text('show');
                });
    

    JS Fiddle demo.

    If you use the attribute for, to define the element to which the label ‘connects’, and also use class-names, then this can be made more generic and useful:

    $('.clickMe').toggle(
                function(){
                    $('#' + $(this).attr('for')).show();
                    $(this).text('hide');
                },
                function(){
                    $('#' + $(this).attr('for')).hide();
                    $(this).text('show');
                });
    

    JS Fiddle demo.

    Bear in mind, though, that the label element is used to associate information with specific input elements, as opposed to a generic identifier for arbitrary elements. Ideally, you should use a span, or div, element rather than a label for this purpose.

    If you do switch to using non-label elements, then the for attribute shouldn’t be used either, in its place I’d suggest (assuming the same connection between what’s currently the label and the div) using a custom data-* attribute (such as data-for) to identify the relationship.

    Note, also, in the above -final- example, the use of the class instead of the id selector, since an id must be unique within the document.

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

Sidebar

Related Questions

How can I get label orientation as in the plot below:
i am beginner of jquery.How can i get the label value through jquery? Below
I was just wondering if you can get two colours in a label so
I can't seem to find a Label control in Silverlight. I get compile errors
How can I get at the Labels data from within my Task model? class
I can get easily see what projects and dlls a single project references from
Logging can get complicated, quickly. Considering that you have some code, how do you
I can get the executable location from the process, how do I get the
I can get the element like this $(#txtEmail) but I'm not sure how to
I am wondering how I can get the value from an asp.net textbox that

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.