'How to retrieve the content of this div? [duplicate]

How do retrieve just "square" from content this div?

<div class="item">
Blue 
<span>•</span> 
Square
<span>•</span>
Infinite
</div>

I tried to use innerText.split(), but i cant figure out how to achieve this,,,

var text = $('.item').innerText.split("");


Solution 1:[1]

I'm no jQuery user (any more), so here's what retrieves the text with the DOM API:

console.log(document.querySelector('.item>span:first-child').nextSibling.textContent)
<div class="item">
Blue 
<span>•</span> 
Square
<span>•</span>
Infinite
</div>

Here's a version that uses split:

console.log(document.querySelector('.item').textContent.split('•')[1])
<div class="item">
Blue 
<span>•</span> 
Square
<span>•</span>
Infinite
</div>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 connexo