$('.post-content').each(function () {
var $this = $(this);
var count = $this.children().length;
if (count > 2) {
var checkExist = setInterval(function () {
if ($this.children('iframe.twitter-tweet').length) {
console.log("Exists!");
sel = $this.children().slice(2);
console.log(sel);
sel.hide();
clearInterval(checkExist);
}
}, 100); // check every 100ms
}
});
<小时/>
Exists!
/blog/ (line 65)
Object[p, p, p, p, p, p, p, iframe#twitter-widget-0.twitter-tweet, blockquote.twitter-tweet, p, p, p, p, p, p]
唯一没有隐藏的元素是 iframe。我的问题是为什么 hide() 仅在渲染 iframe 时应用?
更多详细信息:
<blockquote class="twitter-tweet" lang="pt">
<p>Test your music knowledge with Quiz This It, our weekly trivia challenge. This week's subject: The Strokes <a href="http://t.co/XZIjJO6GSp">http://t.co/XZIjJO6GSp</a>
</p>— NME (@NME) <a href="https://twitter.com/NME/statuses/425328322412052480">20 janeiro 2014</a>
</blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
<小时/>
实际问题演示:
我想隐藏所有元素。
最佳答案
<div id="kite"><blockquote class="twitter-tweet" lang="pt">
<p>Test your music knowledge with Quiz This It, our weekly trivia challenge. This week's subject: The Strokes <a href="http://t.co/XZIjJO6GSp">http://t.co/XZIjJO6GSp</a>
</p>— NME (@NME) <a href="https://twitter.com/NME/statuses/425328322412052480">20 janeiro 2014</a>
</blockquote></div>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
$("#kite").html("");
关于javascript - 使用jquery隐藏iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21272567/