Context: In a form the user needs to add at least one responsible person before submitting the form. This is done with jQuery and Ajax. When submitting the form I need to check if at least one responsible was added using jQuery.
So I add a div with class "checkexists" in a div with ID "verantwoordelijke_added" as soon as the user click the plus button to add a repsonible.
PHP class returns this to jQuery:
$output_array["result"] = '<div id="responsadded_'.$respId.'" class="checkexists" style="line-height:25px">'.$firstname.' '.$lastname.' ('.$_GET["uid"].') <button type="button" class="close eua iid'.$respId.'" id="btn_rm_resp" title="Verwijder" aria-hidden="true">×</button></div>';
$output_array_json = json_encode($output_array);
echo $output_array_json;
jQuery appends this code to the div "verantwoordelijke_added":
$('#verantwoordelijke_added').append(data.result);
Then when submitting the form I would like to check if there are any divs with class "checkexists" in the containing div:
if ($("#verantwoordelijke_added").find(".checkexists").length > 0)
But even if there is a div appended, jQuery can't find it, I guess since it was added "on the fly".
Is there a way arround this?
Thanks a lot,
Mark