jQuery选择器,DIV中的所有跨度

LmC*_*LmC 2 javascript jquery jquery-selectors

 $("#" + mainContent).children("span").replaceWith(function(){ return $(this).text(); });
Run Code Online (Sandbox Code Playgroud)

使用上面的代码行我似乎无法用文本值替换所有跨度.

html看起来像

<div id="bla" contenteditable="true">
<span> bla finds this one</span>
    <div>
        <span> doesnt find me </span>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

如何选择div"bla"中的所有跨度并全部替换它们?

替换工作只是找不到.

Fel*_*ing 10

使用.find [docs]代替.children.它寻找所有后代,而不仅仅是孩子.

查看所有不同遍历方法的jQuery API:http://api.jquery.com/category/traversing/tree-traversal/.