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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:18:47+00:00 2026-05-25T00:18:47+00:00

I have a button as such <button id=toggle_photo> <span id=photo_text>Hide Photos (1)</span> <img class=icon

  • 0

I have a button as such

<button id="toggle_photo">
<span id="photo_text">Hide Photos (1)</span>
<img class="icon" alt="Photos" src="/img/photos-16.png">
</button>

And jQuery / Javascript to change the text upon clicking

$('#toggle_photo').click(function(){
    var text = $('#photo_text').text();
    $('#photo_text').text(
      text.match(/Hide Photos/) ? text.replace("Hide", "Show") : text.replace("Show", "Hide"));
    $('.photo_frame').toggle('slow');
  });

This works the first time the button is clicked and the button text changed from Hide Photo (1) to Show Photo (1). Next, the button html is replaced with new text via an AJAX call, new contents are the same except perhaps for the count, so it might show this instead

<button id="toggle_photo">
<span id="photo_text">Hide Photos (3)</span>
<img class="icon" alt="Photos" src="/img/photos-16.png">
</button>

However, this time the element didn’t trigger a click event, why?

  • 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-25T00:18:47+00:00Added an answer on May 25, 2026 at 12:18 am

    You already gave the answer yourself:

    Next, the button html is replaced with new text via an AJAX call…

    You are removing the current element and adding a new one. The elements might be of the same type and have the same ID, but they are still different elements.

    You either have to bind the event handler again after you changed the HTML, or you use .live() [docs] or .delegate() [docs] to bind the event handler.

    Edit: I’m actually not sure whether you replace the whole button or just its contents. But I assume this is the problem. If this does not help, you have to be more specific and also post the function which replaces the HTML.

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

Sidebar

Related Questions

I have a button as such: <input type=submit id=submit value=Save /> Within jQuery I
I have the following: <div class=btn-group> <input disabled=disabled id=dialogType> <button data-toggle=dropdown class=dropdown-toggle> <span class=caret></span>
I would like to have a button in my window such that if I
I have a button that can have a focus css class associated with it
When I have a button which only changes something in my view (e.g. such
I have a TextBox, GridView and Button such as txtCount, gvCount and btnCount. The
I have a link for menu profile. It has a class called 'user-button'. When
In my rails app, i have a create button as such def create @client
I have a button that correctly wired such that when it is clicked, the
I know that ASP.NET controls such as the button have the postback event model.

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.