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 9245077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:11:04+00:00 2026-06-18T09:11:04+00:00

I am making a jquery on click event that toggles a css class of

  • 0

I am making a jquery on click event that toggles a css class of div#foo (appending it after the existing class) but also needs to toggle the text of the button on click between show/hide.

<script>
$(document).ready(function(){
  $("button.toggler").click(function(){
    $("#foo").toggleClass("maximize");
    $("button.CsToggle").text(!text == "Expand" ? "Hide" : "Expand");
  });
});
</script>

<div id="foo" class="preExistingClass">
  <div>
    <button class="toggler">Expand</button>
  </div>
</div>

I have the class toggle working properly but not the text toggle. Where did I go wrong?

  • 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-18T09:11:05+00:00Added an answer on June 18, 2026 at 9:11 am

    Use the html() function to set the innerHtml of the button. The selector should also be, $("button.toggler"). Also you need to have a variable text available, I’m assuming your business logic will determine how it is set..

    $(document).ready(function(){
      $("button.toggler").click(function(){
        $("#foo").toggleClass("maximize");
        $(this).html($(this).html() == "Expand" ? "Hide" : "Expand");
      });
    });
    

    Working Example: http://jsfiddle.net/z5QVM/

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

Sidebar

Related Questions

I've found posts about making a click event with jQuery for a button, however
I have a div that has a class cls1 . When I click cls1
I have a jQuery autocomplete that works fine making the suggestions but when I
I am making jquery calls to get and getJSON, but cannot access returned values
I'm making a Jquery slideshow. It lists thumbnails, that when clicked on, reveal the
I'm making a jQuery Ajax POST request to a PHP script that returns an
I have a PHP contact form that I'm using with jQuery's AJAX method, but
I'm new to jQuery. I've searched and found some results that might work, but
I have this button making an ajax call using a click event. My goal
Possible Duplicate: Jquery event on a disabled input I am making an edit dialog

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.