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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:17:07+00:00 2026-05-31T23:17:07+00:00

I have the following: somefile.php $(document).ready(function() { var handler = function(data) { var JsDiv

  • 0

I have the following:

somefile.php

$("document").ready(function() {  
    var handler = function(data) {  
    var JsDiv = document.getElementById("somediv");
    JsDiv.innerHTML = data;
  };

$("input[type='checkbox']").change( function() {
    console.log("execute lots of code in this function");
    //I need to execute this part again with the new checkboxes
    //.
    //.
    //.
    //and then
$.ajax({
        url: "ajaxFile.php",
        success: function(data, textStatus, XMLHttpRequest) { handler(data); }
});

  });
});

<div id="somediv">
<input type="checkbox" id="someid1" value="anything1" /> checkbox1
<input type="checkbox" id="someid2" value="anything2" /> checkbox2
</div>


ajaxFile.php
echo "
<input type='checkbox' id='someid3' value='anything3' /> checkbox3 <br />
<input type='checkbox' id='someid4' value='anything4' /> checkbox4
";


The problem is that $(“input[type=’checkbox’]”).change( function() {}) gets executed just fine when I first load the page, but once the new checkboxes have been loaded via ajax, they are not bounded to that function. I’ve seen things about bind() and live() but I don’t quite get how to bind the new checkboxes to the function that I’ve already defined. I need to execute some code that is inside .change().. I would extract that code outside of .change() and call that function afterwards but I am not too sure how to do so.

If my question is not clear, please let me know and I will re-phrase. Thank you for your help.

  • 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-31T23:17:08+00:00Added an answer on May 31, 2026 at 11:17 pm

    You just need to delegate to an ancestor listener that doesn’t get destroyed. The below snippet uses .on() with delegation syntax and is a replacement for your .change() event listener.

    $("#someContainer").on("change", "input[type='checkbox']", function() {
      console.log("execute lots of code in this function");
    });
    

    someContainer is obviously (I hope) a placeholder name. It just means any container wrapping around your target inputs. Do your best to identify the closest ancestor, as this will have the most performance benefits. But if you absolutely MUST, you could always use document:

    $(document).on("change" /* .....etc.... */);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function: var id = 10; var type = Type A;
I have got html as below <a href= data-href=/somefile.php?id=10&refcode=/test.php>Hello</a> and I need to replace
I have the following code: String inputFile = somefile.txt; FileInputStream in = new FileInputStream(inputFile);
I have an .aspx file that outputs an image using the following methods: Server.MapPath(somefile.png)
I have the following code: p.StartInfo.FileName = notepad.exe; p.StartInfo.Arguments = somefile.txt; p.Start(); When somefile.txt
I have the following text string: $ABCD(file=somefile.txt)$' />Some more text followed by a dollar
Consider the following. I have two exported constants as follows: // somefile.h extern const
I have a Show in folder button which executes the following: explorer.exe /select,C:\dir\somefile.txt In
I have the following code: <div id=object-container> <object data=some-file.swf> <param name=src value=some-file.swf /> </object>
i am working on a regex match function in python. i have the following

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.