0

I've got a button that I'm using to show/hide a follow and content. I've been able to change the button to change from saying "View Images as Gallery" to "Hide Image Gallery" - but I cannot get it to revert to "View Images as Gallery" when clicked again. Here is the jQuery:

jQuery(function(){
    jQuery(".homeImageGalleryButton").click(function () {
        jQuery(".homeHiddenGallery").toggle();
        jQuery(".homeImageGalleryButton").toggleClass('homeImageGalleryButtonHide');
        jQuery(".homeImageGalleryButtonHide").html("Hide Image Gallery");
    });
});

Here is the HTML

<a class="et_pb_button et_pb_button_0 homeImageGalleryButton showGalleryButton">View Images As Gallery</a>

What am I not getting right here? :)

I've tried adating the code here: Change button text - but with no success.

TomN
  • 23
  • 5
  • You are replacing the content of the button (`.html("Hide Image Gallery")`) but you are not switching it back at any point. You need to check the current state of the button and use that to decide which text to switch to. You could check using `jQuery(this).hasClass('homeImageGalleryButtonHide')`. Have another look at the question you have linked to as it does answer your question :) – frobinsonj Feb 19 '20 at 15:05
  • 1
    https://stackoverflow.com/questions/4326910/toggle-text-with-jquery – Pete Feb 19 '20 at 15:07

0 Answers0