如何得到第二个字

3 javascript jquery jquery-selectors

我有以下HTML:

<div class="test">
    First
    <p></p>
    Second
    <p></p>
    Third
</div>
Run Code Online (Sandbox Code Playgroud)

Second在这种情况下我怎么能得到这个词?

Eli*_*Eli 5

您可以使用jQuery contents()和eq():

var second = $('.test').contents().filter(function() {
                 return this.nodeType == Node.TEXT_NODE;
             }).eq(1).text(); 
Run Code Online (Sandbox Code Playgroud)

Working Demo