类选择器上的
.html()
函数 ($('.class').html()
) 仅适用于与其匹配的第一个元素。我想获取类 .class
的所有元素的值。
最佳答案
您正在选择具有 .class
类的所有元素,但要收集所有 html 内容,您需要遍历所有这些元素:
var fullHtml;
$('.class').each(function() {
fullHtml += $(this).html();
});
通过其中包含的文本搜索项目:
$('.class:contains("My Something to search")').each(function() {
// do somethign with that
});
关于javascript - 所有匹配元素的 jQuery .html(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7518086/