doniyor doniyor - 5 months ago 9
jQuery Question

Get text separetly

I have following html

<div>
<span>123</span>
<span>456<span>789</span></span>
</div>


When I try to get text it gives in one line

$('div').text() ---> '123456789'


Question: How to get text separetly like:

123 456 789

Answer

For getting text separately, you need to loop through all span and get its text:

$('div span').each(function(){
  alert($(this).text());
});
Comments