I'm using the following script:
$.ajax({
url: urls.notifications,
type: 'POST',
dataType: 'html',
data: {timestamp: notification_timestamp},
success: function(response) {
var responseAmt = $(response).find("li").length;
alert(responseAmt);
}
});
This is the response I get:
<li class="notification" data-notification-id="117">
<a href="http://local.dev/user/admin">
<div class="avatar-container">
<img src="http://www.gravatar.com/avatar/64e1b8d34f425d19e1ee2ea7236d3028">
</div>
</a>
<div class="content">
<p class="message">
<a href="http://local.dev/user/admin"><b>admin</b></a> has commented on your post.
<a href="http://local.dev/gag/image-example-10">
<b>Check it out</b>!
</a>
</p>
<p class="timestamp">
<i class="fa fa-clock-o fa-fw"></i>
5 seconds ago </p>
</div>
</li>
Each response can contain 1 or many <li>
's like that, and I need to count them to update responseAmt
variable, which holds the amount of notifications returned.
I tried:
$(response).find("li").size(); //shows 0
$(response).find("li").length; //shows 0
But this one works correctly:
$(response).find(".content").length; //shows correct amount
Anyone knows why I can't count <li>
's?