<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
var commentUrl = 'comment.jsp';
$('.privateTimeline').click(function() {
$.ajax({
url: commentUrl,
type:'post',
data:{
no : $(this).find('.no').text() // working!
},
success:function(data){
if( $(this).children('.comment').is(':hidden') ) { // not working!
$(this).find('.comment').slideDown(400); // not working!
$(this).find('.comment').html(data); // not working!
}
else {
$(this).find('.comment').slidUp(400); // not working!
}
});
})
</script>
This should work :
var $target =$('.privateTimeline');
$target.click(function() {
$.ajax({
url: commentUrl,
type:'post',
data:{
no : $(this).find('.no').text() // working!
},
success:function(data){
if( $target.children('.comment').is(':hidden') ) { // not working!
$target.find('.comment').slideDown(400); // not working!
$target.find('.comment').html(data); // not working!
}
else {
$target.find('.comment').slidUp(400); // not working!
}
}
});
});
In success:function(data){}
, $(this)
doesnt point to $('.privateTimeline')
anymore. So you access it using its unique selector.
Also, you had your closing brackets wrong, so I corrected that for you.