'jQuery: Get text when selector includes elements and text

With the selector $('div.alert') I get the following:

<div class="alert alert-success alert-dismissible fade show" role="alert">
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
Foo Bar is now locked
</div>

I want to return the text Foo Bar is now locked. But using $('div.alert').text() all I get is ...text() is not a function. How to retrieve the text?



Sources

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

Source: Stack Overflow

Solution Source