<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)
$("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)
| 归档时间: |
|
| 查看次数: |
2756 次 |
| 最近记录: |