youtube embed code example

Example 1: autoplay youtube video

// Add this to your URL
?autoplay=1&mute=1
// example
https://www.youtube.com/embed/9QTojZVR_Ec?autoplay=1&mute=1

Example 2: youtube embed video

//Author:Mohammad Arman Khan

Example 3: get youtube embed code from url

<----------------------------------- HTML ---------------------------------->
YouTube ID: 


Embed code:


function getId(url) {
    var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
    var match = url.match(regExp);

    if (match && match[2].length == 11) {
        return match[2];
    } else {
        return 'error';
    }
}
<----------------------------------- JS ---------------------------------->
var myId = getId('http://www.youtube.com/watch?v=zbYf5_S7oJo');

$('#myId').html(myId);

$('#myCode').html('');

Example 4: embedded youtube