1

I am interested in checking whether some checkboxes are checked to send a ajax call. But these checkboxes were created dynamically and I cannot do this using selectors. First I was thinking about checking how many checkboxes are, in the containing div element. But this seems to be impossible. My code in general looks like this.

function setup(){
   //.... Some data is appended in a container. The data is gotten from a php script
}

function update {
//... this function reads values from elements from page, works with selectors for static elements, selectors, don't work with dynamic ones
}

$(document).ready(function() {
    setup();
    update();
});

So basically the dynamic element's are appended to the HTML when setup is called. Then when calling update and I am to retrieve data I cannot. For example (in update(), where #boje is an element generated dynamically setup):

var temp = $("#boje").children().length;
alert(temp);

I get 0. When I should really get 5, for a given example. Meaning that this isn't how it is supposed to be done. How do I do this?

Bocko
  • 33
  • 5

2 Answers2

0

Try below code

function setup(callback){
   //.... Some data is appended in a container. The data is gotten from a php script
callback(true);
}

function update {
//... this function reads values from elements from page, works with selectors for static elements, selectors, don't work with dynamic ones
}

$(document).ready(function() {
    setup(function(){
       // once HTML is generated and bind to the dom then call the update function
       update();
    });
});
ganesh deshmukh
  • 314
  • 4
  • 17
-1

i think this is already answered, hope you got your answer from here jQuery not detecting clicks on dynamically inserted element

Community
  • 1
  • 1
Gautam Rai
  • 2,445
  • 2
  • 21
  • 31