假设我的 html 如下:
<h3 class="search-result-title">
This is a test
<small class="search-result-subtitle">
Some more explanation
</small>
</h3>
如何过滤文本This is a test
没有 small
?
编辑:我将它与 symfony Dom Crawler 一起使用。
所以我有filter(a. h3 search-result-title);
但我不想要 small
的内容元素。
最佳答案
您可以使用此代码仅获取 h3 元素的文本。
document.querySelector('.search-result-title').firstChild.textContent
关于jquery - css不选择子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34160694/