如果我有以下html结构:
<ol>
<li>
Text A <span>Other text</span>, Text B
</li>
<li>
Text A <span>Other text</span>, Text B
</li>
</ol>如何使用jQuery迭代每个列表项,并分别更改文本A和文本B的文本,而不影响跨度及其内容?
发布于 2015-04-20 18:12:56
$("ol li").contents().filter(function() {
return this.nodeType === 3;}
);换句话说,小提琴
$("ol li").contents().filter(function() {
return this.nodeType === 3;}
).each(function(i, obj){
//your code using i, obj or this for choose
this.textContent = "change";
});https://stackoverflow.com/questions/29755192
复制相似问题