Reputation: 181
I am triying to add ajax loaded content in child element of current div item, but it not works , unable to find out where is the problem.
here is HTML code:
<div class="thumb-pitch">
<span class="pitch-count" ></span>
</div>
<div class="thumb-pitch">
<span class="ditch-count"></span>
</div>
JS code:
$('.thumb-pitch').click(function() {
var id= $(this).attr('cid');
var dataString = 'idea_id='+ id;
$.ajax({
type: 'POST',
url:"<?php echo base_url();?>users/user_votes/user_pitch",
data:dataString,
success: function(response) {
//alert(response);
$(this).find('span').html(response);
}
});
});
Upvotes: 0
Views: 609
Reputation: 302
You can use children() for this
$(this).children('span').html(response);
Upvotes: 0
Reputation: 133403
You need to store the reference of $(this)
in a variable and then use that variable in the sucess callback handler.
Use
$('.thumb-pitch').click(function() {
var id = $(this).attr('cid');
var $this = $(this); //Store this reference in a variable
$.ajax({
type: 'POST',
url: "<?php echo base_url();?>users/user_votes/user_pitch",
data: {"idea_id" : id},
success: function(response) {
//alert(response);
$this.find('span').html(response); //Use the reference variable here
}
});
});
Upvotes: 1