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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:13:58+00:00 2026-05-30T15:13:58+00:00

I created an ajax tab navigation with html being inserted into the page. the

  • 0

I created an ajax tab navigation with html being inserted into the page. the code looks like this:

$.ajax({
        type: 'POST',
        url: 'main/ajaxjson/load_course_details',
        data: {page : which, course_id: id},
        success: function(home){

            $('#ajax-content ').hide();
            $('#ajax-content').empty().append(home);
            $('#ajax-content').fadeIn(); 
        }

    });

ok…so I append my markup into my html. Now I need to select dom elements from the inserted html, but I can not. I have the following code:

<a href="javascript:;" class="light-button">Next</a>
<select id="chapters-select">
    <?php foreach ($chapters as $chapter) : ?>
    <option value="<?php echo $chapter->id; ?>"><?php echo $chapter->title; ?></option>
    <?php endforeach; ?>
</select>

Here I generate the select options dynamically. When I try to do this:

$('#chapters-select').change(function(){
    alert('changed');
});

it doesn’t work.
How can I use javascript after I append the html via ajax ?

  • 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-30T15:14:00+00:00Added an answer on May 30, 2026 at 3:14 pm

    Use delegate event like on for version 1.7+

    $('body').on('change', '#chapters-select', function(){
        alert('changed');
    });
    

    To increase performance instead of body you should write the closest static(Not added dynamic with ajax or javascript) element that holds “chapters-select

    If you are using older version of jQuery choose the appropriate method with the following table:

    $(selector).live(events, data, handler);                // jQuery 1.3+  
    $(document).delegate(selector, events, data, handler);  // jQuery 1.4.3+  
    $(document).on(events, selector, data, handler);        // jQuery 1.7+  
    

    on docs:

    When a selector is provided, the event handler is referred to as delegated. The handler is not called when the event occurs directly on the bound element, but only for descendants (inner elements) that match the selector. jQuery bubbles the event from the event target up to the element where the handler is attached (i.e., innermost to outermost element) and runs the handler for any elements along that path matching the selector.

    Event handlers are bound only to the currently selected elements; they
    must exist on the page at the time your code makes the call to .on().
    To ensure the elements are present and can be selected, perform event
    binding inside a document ready handler for elements that are in the
    HTML markup on the page. If new HTML is being injected into the page,
    select the elements and attach event handlers after the new HTML is
    placed into the page. Or, use delegated events to attach an event
    handler, as described next.

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

Sidebar

Related Questions

I have this jQuery ajax navigation tabs plugin that I created using some help
I have created a page which is autorefreshing via ajax requests. On this page
My form has a custom element like below, created using custom ajax: <select jwcid=testtest
I've created a Wcf Service to back a Ajax page (.Net 3.5). It's hosted
I have an index page for listing products. From this page I would like
I've created an ajax driven flot line chart that I would like to have
I have a tab panel like this: var tab1 = { id: 'section1', title:
I have a tab panel like this: var tab1 = { id: 'section1', title:
I inserted an ASP.NET check box list control inside an AJAX tab container. Now
I created an index.html page that have 3 different tabs. With the function tabs()

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.