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.

http://jsbin.com/ocefeq/1/edit


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -