JQuery 从 Div 中抓取文本减去子元素

joh*_*y 5 2 html javascript jquery

有没有一种简单的方法可以从这个 div 中获取文本而不获取任何子元素?

<div id="someselector">
   <strong>Title Text Unwanted</strong> This is the text I need
</div> 
Run Code Online (Sandbox Code Playgroud)

我知道我可能可以在强上做一个子串。我只是想知道是否有一个函数可以在 jQuery 中自动为我完成,例如:

 $('#someselector').html().not('strong').text()
Run Code Online (Sandbox Code Playgroud)

小智 5

它基本上归结为:

$("#someselector").clone().children().remove().end().text();
Run Code Online (Sandbox Code Playgroud)

首先,克隆元素,获取其子元素,删除它们,然后获取克隆的文本。