Reputation: 3697
I am trying to get the youtube src from from within an iframe embed code and pass it as a variable.
For example, if my youtube embed code is:
<iframe width="1024" height="576" src="https://www.youtube.com/embed/rfxESg1_hEA?feature=oembed"frameborder="0"allowfullscreen></iframe>
I'm trying to get https://www.youtube.com/embed/rfxESg1_hEA
Is there a way to do this with jQuery?
Upvotes: 2
Views: 2436
Reputation: 1333
Try this:
var src = $("iframe").attr("src").split('?')[0];
alert(src);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<iframe width="1024" height="576" src="https://www.youtube.com/embed/rfxESg1_hEA?feature=oembed"frameborder="0"allowfullscreen"></iframe>
Upvotes: 5