Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created July 28, 2011 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rwaldron/1111943 to your computer and use it in GitHub Desktop.
Save rwaldron/1111943 to your computer and use it in GitHub Desktop.
Get the document of an iframe element
var iframe = document.getElementById("my-iframe"),
iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document;
console.log( iframeDoc );
@speedjudy
Copy link

To get the value of the data-videoid attribute in the iframe element using JavaScript, you can use the following code:

// get iframe element using its id
var iframe = document.getElementById("your-iframe-id");

// get the value of the data-videoid attribute
var dataVideoid = iframe.getAttribute("data-videoid");

// do something with the data-videoid value
console.log(dataVideoid);

Replace your-iframe-id with the actual id of the iframe in your page. This code will retrieve the iframe element using its id and then use the getAttribute() method to retrieve the value of the data-videoid attribute. You can then use this value as needed in your code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment