如果是YouTube嵌入,请定位iframe [英] Target iframe if it is a YouTube embed
本文介绍了如果是YouTube嵌入,请定位iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将页面上的所有YouTube嵌入包装成div。目前,我可以在div中包含所有 iframe:
I want to wrap all YouTube embeds on the page into a div. Currently, I can wrap all iframes in a div with:
jQuery(document).ready(function(){
jQuery('iframe').wrap("<div class='ta-vid-cont'></div>");
});
但我想只定位YouTube嵌入的iframe。我该怎么做?
But I want to target only iframes that are YouTube Embeds. How can I do this?
典型的YouTube嵌入式看起来像:
Typical YouTube embed looks like:
<iframe width="700" height="394" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/d3LDQMKLc?feature=oembed&wmode=transparent">
推荐答案
可以使用 Attrubute包含
selector
Can use Attrubute Contains
selector
$('iframe[src*="youtube"]').wrap("<div class='ta-vid-cont'></div>");
这篇关于如果是YouTube嵌入,请定位iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文