Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to target only youtube iframe urls?

Tags:

jquery

youtube

I'm looking for a way to target this jquery only at src url's that have "youtube.com" in them. I've tried using the :contains selector but I can't get it working correctly.

jQuery(document).ready(function($){

    $('iframe').each(function() {
        var url = $(this).attr("src")
        $(this).attr("src",url+"&wmode=transparent")
    }); 

});
like image 893
Bryan Casler Avatar asked Dec 04 '22 17:12

Bryan Casler


1 Answers

Use the attribute selector to target only iframes with a src containing youtube.com:

jQuery(document).ready(function($){

    $('iframe[src*="youtube.com"]').each(function() {
        var url = $(this).attr("src")
        $(this).attr("src",url+"&wmode=transparent")
    }); 

});
like image 186
Aaron Avatar answered Dec 22 '22 00:12

Aaron