jquery - Find each div with specified class -
var data='<div class="shout_msg"> <span class="username">3</span> <span class="message">hello</span> </div> <div class="shout_msg"> <span class="username">0</span> <span class="message">yo</span> </div> <div class="shout_msg"> <span class="username">0</span> <span class="message">hey</span> </div> <div class="shout_msg"> <span class="username">0</span> <span class="message">haha</span> </div>'; $(data).find(".shout_msg").each(function(index){ console.log($(this).find("span.username").text() ); }); its not returning anything. data, shown here in variable, coming ajax request. in case doing silly mistake or something. please correct me.
you want use filter in case since you're not searching inside objects.
$(data).filter(".shout_msg").each(function(index){ console.log( $(this).find("span.username").text() ); }); here's quick demo you.
Comments
Post a Comment