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

  • Home
  • SEARCH
  • 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 8656587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:18:46+00:00 2026-06-12T15:18:46+00:00

I have a Jquery event which does not trigger every time: http://jsfiddle.net/LphjL/ My code:

  • 0

I have a Jquery event which does not trigger every time:

http://jsfiddle.net/LphjL/

My code:

thisWebsite = websiteInitialization ();

function websiteInitialization () {
    companyName = "name";
    var thisWebsite = new websiteConstructor(companyName);
    return thisWebsite;
}

function websiteConstructor(companyName) {
  this.companyName=companyName;
}

function ajaxUpdateDB(websiteElement, value) {
    return $.post('/echo/html/',{html: "<p>Text echoed back to request</p>",delay: 3}
                ,function(a){}
                ,"json"
        );    
}

function updateDatabase(websiteElement, value) {
    var promise = ajaxUpdateDB(websiteElement, value);
    promise.complete(function () {
        thisWebsite[websiteElement] = value;
    });
}


$(document).ready(function() {

    $(".websiteElement").change(function() {
        updateDatabase( $(this).attr('id'), $(this).val() );
    });

    $("#infos").click(function() {
        htmlCode =    "<input class='websiteElement' id='companyName' type='text' value='"+thisWebsite.companyName+"'>";
        $("#panel-content").html(htmlCode);
    });

    $("#homepage").click(function() {
        htmlCode = "homepage";
        $("#panel-content").html(htmlCode);
    });

});
​

As you can see in the jsfiddle, the first time the input field is updated the Ajax is triggered, but:

if you click on ‘Homepage’, then click back on ‘Generic infos’ and update the input field again this time the Ajax is NOT triggered: $(".websiteElement").change event is not called the second time.

  • 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-12T15:18:48+00:00Added an answer on June 12, 2026 at 3:18 pm

    You need to bind the event using event delegation, or rebind the event after you replace the element. Below is the event delegation option:

    $("#panel-content").on("change",".websiteElement",function() {
        updateDatabase( $(this).attr('id'), $(this).val() );
    });
    

    If the event is bound directly on the element, the event will be lost when the element is replaced/removed.

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

Sidebar

Related Questions

I have some jQuery code which works great in Firefox and Chrome, but does
I have a custom jQuery plugin which binds a change event to a form
I have a jQuery event handler that reacts to every change in an: <input
Suppose I have this jQuery code. $(document).delegate('a[title]', 'click', function(event) { var txt = //
Does jquery/javascript have any event model that you can attach to your objects? Basically
I have some code bound to the blur() event in jQuery: $('input[type=text]').blur(function () {
I have this jQuery code where I have a click event on a <tr>
I have a jQuery code which works perfect on desktop browsers; $(span#checkbox_err).mouseout(function () {
How document.ready event is implemented in jQuery. I mean whether they have used defer(which
I have some jQuery code that highlights which radio button is checked by turning

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.