<ul id="months">
<?php foreach ($months as $key => $value) { ?>
<?php if ($key != 0 && array_key_exists($key, $monthArray) && date("m") > $key) { ?>
<li id="<?= $key ?>"><a href="#" rel="nofollow"><?= $value ?></a></li>
<?php
}
}
?>
below is the jquery code
$("#year").change(function(){
// alert($(this).val());
$.ajax({
type: 'get',
url: 'ay/templates/frontend/_previous_months.tpl.php',
data: 'year=' + $(this).val(),
success: function(data) {
$("#months").html(data);`
}
});
});
Problem : when i first time request partial i get proper result, but after when i get months partial i can t access jquery from it,
below is the jquery function which i need to access after when i get my parial(before making above ajax call, i can access below jquery function when i click on li item)
$("#months li").click(function(){
alert("aaaaaaaaaaaaaaaaaaa");
$.ajax({
type: 'get',
url: 'ay/templates/frontend/_previous_charities.tpl.php',
data: 'month=' + $(this).attr("id") + '&year=' + $('#year').val(),
success: function(data) {
if(data == 'false'){
$("#charity_result").html("No previous charity in selected Month");
}else{
$('#charity_result').fadeOut('slow');
// $('#ajax-result').fadeIn('slow');
$('#charity_result').fadeIn('slow');
$("#charity_result").html(data);
}
}
});
});
I think your
clickevent is not added to your#months li.Try using the live method: http://api.jquery.com/live/
Instead of:
$("#months li").click(function() {use this:
$("#months li").live('click', function() {