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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:19:29+00:00 2026-05-13T14:19:29+00:00

is it possible that javascript doesnt apply to elements created trough an ajax request?

  • 0

is it possible that javascript doesnt apply to elements created trough an ajax request?
practically i have a tree of elements like parents and children with a dept of more levels.

i have the root elements on the index page and on click i can retrive the children trough this request:

var get_children = function() {
 pid = $(this).attr("id");
 //var parentid = pid
    // store value in data variable
    var data = { par: pid };
    $.getJSON("/holz/children/",data,
        function(data){
      //remove the box if it already exists
      $("#parid-" + pid ).remove();
            // Add the messages div to the container
            $("#container").append("<div class='box' id='parid-" + pid + "'></div>");
            //create the id set for the box
            boxid = "#parid-"+pid
            //insert the elements one after each other with the id set to the elements pk  
            $.each(data, function(i,item){
                $(boxid).append('<p><a '+'id="'+item.pk+'"'+' class="element" href="#">'+item.fields.title +' ( id = '+ item.pk+' )'+'</a>'+'</p>');
            });
        }
    );
  return false;
};

the problem is that i cant go deeper because the request doenst apply on the elements i got from the first request. the ajax request calls a django view which should (and it does in the on the first element) and returns a json reponse which i use to create a box with the children.

what am i doing wrong?

thx

  • 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-13T14:19:30+00:00Added an answer on May 13, 2026 at 2:19 pm

    I’m not sure I fully understand but it sounds like you want an onclick eventhandler to apply to all domelements with a certain css class .element. Am I right?

    If so then just use jQuery’s live() event binder syntax. This will allow you to bind an event to all dom elements that match a given selector now, and in the future.

    To use some of your own code as an example:

    $('div.box').live('click', function() {
        alert('you clicked me!');
    });
    
    $("#container").append("<div class='box' id='parid-" + 1 + "'></div>");
    

    In the example above the div that we added dynamically will have our click event bound to it since we used the jquery api to insert it.

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

Sidebar

Related Questions

Possible Duplicate: JavaScript: formatting number with exactly two decimals Now that I have got
Is it possible to subclass and inherit from javascript Arrays? I'd like to have
Do you know if it is possible to make sure that a JavaScript script
Is it possible to make JavaScript retrieve a file that is above the web
Is it possible, in Javascript, to prompt user for downloading a file that isn't
Is it possible that when you have a webpage, when you open the PDF,
It is quite possible that I may not have got the point, but I
is that possible to call Javascript function without supply all the parameters? I come
as far as I can see, it is possible to verify in JavaScript that
is it possible to have <a href=index.php > click </a> that doesn't change page

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.