jquery选择文本

3 javascript jquery

<div>select this<strong>dfdfdf</strong></div>
<div><span>something</span>select this<strong>dfdfdf</strong></div>
Run Code Online (Sandbox Code Playgroud)

我如何使用jquery或只是javascript来选择div标签的值,但不包括任何子元素

//output
select this
Run Code Online (Sandbox Code Playgroud)

geo*_*wa4 5

$("div").contents().each(function(i) {
    //the function is applied on the node. 
    //therefore, the `this` keyword is the current node.
    //check if the current element is a text node, if so do something with it
});
Run Code Online (Sandbox Code Playgroud)