How can I put an iframe youtube on a frame with icon close. example:- If I want to put the iframe below on frame with icon close, and if I click on icon close the iframe youtube will disappear, how can I do this?
<iframe width="440" height="215" src="http://www.youtube.com/embed/OyRQio7GfLU" frameborder="0" allowfullscreen></iframe>
Thanks
On a computer, go to the YouTube video or playlist you want to embed. From the list of Share options, click Embed. From the box that appears, copy the HTML code. Paste the code into your website HTML.
To change YouTube embed iframe video, we just need to change the src attribute value of the iframe with the new YouTube video embed URL using javaScript iframe src property.
Using the contentWindow.postMessage() sends a message to the particular element. In our case, we will give the command to stop the YouTube video and invoke the stopVideo() function using this method. We can either stop or pause the YouTube video using this method.
I'm not sure by 100% if this is what did you expect, but I hope I've helped you.
$(".button").click(function() {
$("#x").addClass('hide');
});
.frame {
height: auto;
width: auto;
padding: 20px;
border: 1px solid black;
position: relative;
}
.button {
position: absolute;
top: 5px;
right: 5px;
height: 20px;
width: 20px;
background-color: black;
color: white;
}
.content {
display: block;
}
.hide {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="frame">
<button class='button'>X</button>
<iframe id='x' class='content' width="440" height="215" src="http://www.youtube.com/embed/OyRQio7GfLU" frameborder="0" allowfullscreen></iframe>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With