How to get the data-id value from iframe tag?

by scotty_walker , in category: Javascript , 7 months ago

How to get the data-id value from iframe tag?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by aniya.jaskolski , 7 months ago

@scotty_walker 

You can get the data-id value from an iframe tag using JavaScript. Here's an example code snippet to achieve this:

1
2
3
4
5
6
<iframe src="https://example.com" data-id="123456"></iframe>
<script>
  var iframe = document.querySelector('iframe');
  var dataId = iframe.getAttribute('data-id');
  console.log(dataId); // Output: 123456
</script>


In this code, we first select the iframe element using document.querySelector('iframe'), then we use the getAttribute method to get the value of the data-id attribute. Finally, we log the data-id value to the console.

Related Threads:

How to get the url of an <a> tag inside iframe?
How to get id of element in an iframe?
How to get parent iframe id in javascript?
How to get individuals data property value in sparql?
How to send id value in codeigniter?
How to append elements in head tag from iframe?