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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:48:12+00:00 2026-05-29T03:48:12+00:00

I initially got this code and all works well: <div class=rm> <button id=sub type=submit>

  • 0

I initially got this code and all works well:

<div class="rm">
        <button id="sub" type="submit">
            <span>Registo</span>
        </button>
    </div>

   <script type="text/javascript">
    $(document).ready(function() {
        $(".rm>#sub").click(function(event) {
            event.preventDefault();
            var formdata = $("#custom").serialize();
            $.ajax({
                url: "dojo/insert.php",
                type: "post",
                dataType: "json",
                data: formdata,
                success: function(data) {
                    switch (data.livre) {

                    case 'error':
                        $(".rm").html('<button id="sub"  type="submit"><span>Rever</span></button>');
                        break;                    

                    default:
                        $('#paginas').delay(50).load('profile_empresa_3.php');          
                        break;
                    }
                }
            });
            return false;              
        });
    });
    </script>

The problem now. When i add $(".rm").html("") with a button with the same id. If i click in this new button the page is reloaded. My question is. If the button added has the same id, why the click handler is not repeated ?

thanks

  • 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-29T03:48:13+00:00Added an answer on May 29, 2026 at 3:48 am

    At the time you bind the event handler to $(".rm > #sub"), the new element does not exist yet, so jQuery cannot bind the handler to it.

    You could either rebind the event handler, or bind it to $('.rm') instead and use event delegation (using .on()) :

    $('.rm').on('click', '#sub', function() { // or use button instead of #sub
       //...
    });
    

    But instead of replacing the whole element, it seems you could just change its text content:

    $('#sub span').text('Rever');
    // or
    $('.rm button span').text('Rever');
    

    Also note that IDs are supposed to be unique, having two elements in the DOM with the same ID is invalid.

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

Sidebar

Related Questions

Hi I've got a DIV section that has only its title visible initially. What
I was reading this but I didn't really got from there what request-type the
Initially I thought this was going to work, but now I understand it won't
I initially designed my system following the s# architecture example outlined in this codeproject
So I'm using the jQuery date picker, and it works well. I am using
I've got a script that disables a button input control, empties a table body
I am using YUICompressor to compress my jQuery plugins. Initially I got a lot
Initially i declared a 2D array in this way: subUrb = [[NSArray alloc] initWithObjects:
I have a class that looks like this: class SearchService include Mongoid::Document key :name,
My aim before writing this code was to just practice and learn more about

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.