我正在使用名为Embedly的服务来设置来自Google Feedburner的RSS Feed。我有一个示例代码:JsFiddle
如果仔细观察,您会在每个标题的末尾看到来源(CNN)。这被称为.provider
我想摆脱整个div(.embed)如果CNN所在的单词是div(意思是重复的)在div中,.description
或a
我尝试了很多东西,这是其中一个非常简单的代码:
$('.embed').each(function() {
if($('.embed a:first **could also be .description**', this).text() == $('.provider', this).text())
$(this).remove();
});
我无法弄清楚为什么它不起作用。我还使用on
和live
点击它,但没有运气。
我刚刚意识到文件已经存在'嵌入'。我添加了一个带有点击事件的按钮,您可以在嵌入加载后点击:http://jsfiddle.net/2VBSX/37/
答案 0 :(得分:2)
您可以使用success事件从数据中过滤提供程序类,如下所示:
<强> EDITED 强>
$('div.newscontainer').embedly({
key: ':3eccf441bf0f43acbb076da9817af27d',
success: function(oembed, dict) {
output = $(oembed['code']);
description = $(oembed['code']).find(".description").text();
var regex =new RegExp(output.find('.provider').text(),"i");
if(regex.exec(description) == null ) {
$(dict["node"]).parent().html(output);
}
output.find("a:eq(0)").text(); // First
output.find("a:eq(1)").text(); // Provider
}
});
答案 1 :(得分:0)
你想要的是that吗?
var regex = /CNN/;
$('.embed').each(function(index, element) {
if (regex.exec($('.embed a:first').text()) != null
&& regex.exec($('.provider').text()) != null) {
element.remove();
}
});