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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:53:11+00:00 2026-06-09T03:53:11+00:00

The scenario I’m getting a page by JQuery ajax call, and show as a

  • 0

The scenario

I’m getting a page by JQuery ajax call, and show as a pop-up. The reason why i’m doing so is the page can be accessed without javascript also. The page itself contains some drop-down lists and buttons. In the javascript disabled version the state of the page maintained by passing the selected values to and from the server which uses php. Therefore i intended to do the same with the javascript and in such case the previous html elements need to be replaced with ajax response. I made an extensive search over the web, but helpless.

The problem

After replacing, the elements losing their event data,

how to preserve or re-bind the events associated with them?

The code i have been trying to implement is

    $('#search-main a').on('click', function(e){
        e.preventDefault();
        $('#search-advanced').remove();
        var target = $(this).attr('href');
        var res = $.get(target, function(data){
            $('body').append($(data).find('#search-advanced'));
            $('#search-advanced').addClass('row reveal-modal');
            $('#search-advanced')
            .css('top', 80)
            .css('border-radius' , '5px')
            .css('padding-left' , '0px')
            .css('padding-right' , '0px');

            $('#search-advanced input[name="select_filter"]').remove();
            $('#search-advanced .custom.dropdown').on('change', function(){
                $('#search-advanced form').trigger('submit');
            });                 

            $('#search-advanced form').on('submit', function(e){
                e.preventDefault();
                var params = $('#search-advanced form').serialize();
                $.get(target, params, function(data){
 // This is where I'm encountering the problem
 // The first time it works fine, 
 //     but for the second time the change event not get triggered
                    $('#search-advanced form').replaceWith($(data).find('#search-advanced form'));
                    $('#search-advanced input[name="select_filter"]').remove();
                    console.log($(data).find('#search-advanced .custom.dropdown'));
                });
            });

            $('#search-advanced').append('<a class="close-reveal-modal">&#215;</a>');
            $('#search-advanced').reveal({
                animation: 'fade', 
                closeOnBackgroundClick: false
            });
        });
    });

I’m not sure about the elegance of this approach, any suggestion to solve or different approach will be very thankful.

I already tried the following links

  • jQuery event not triggered
  • jQuery load-event after replaceWith
  • Maintain jQuery onChange After a Replacewith
  • 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-09T03:53:13+00:00Added an answer on June 9, 2026 at 3:53 am

    I’m not sure why you’re destroying the original form in the first place. If you just need to reset it, there are probably better ways.

    But given that you are destroying the form, and therefore its handlers, you could bind the handler to the #search-advanced element, and use the event delegation signature of .on.

      // v--event is bound here          v--and will trigger on the form element
    $('#search-advanced').on('submit', "form", function(e){
        e.preventDefault();
        var params = $('#search-advanced form').serialize();
        $.get(target, params, function(data){
            $('#search-advanced form').replaceWith($(data).find('#search-advanced form'));
            $('#search-advanced input[name="select_filter"]').remove();
            console.log($(data).find('#search-advanced .custom.dropdown'));
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: User loads a page, image is being generated, show loading bar, notification event
Scenario: Every page on the website will have a menu bar at the top
Scenario: I start out in my app's main page. I navigate to sub-page A,
Scenario: I've hundreds of applications instances running on client machines doing a certain job.
Scenario: I am working on a Android project where in one particular openGL page,
Scenario: At our company, we have enabled httpCompression for our website. This website (call
Scenario: A simple html page exists with few buttons on Top (e.g. day, week)
Scenario is I have a application relative url like ~/path/to/page.aspx?query=string. I need to programatically
Scenario: My general portal is hosted in IIS using ASP.NET and a login page.
Scenario: I have a webpage that needs to make XMLRPC calls from Javascript, and

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.