Is there a way to do the following in JavaScript?
<html>
<body>
<div class="calendar">
<iframe></iframe>
</div>
</body>
</html>
To get a div by class name:
var allDivs = document.getElementsByClassName("calendar");
Assuming there's only one
var calendarDiv = document.getElementsByClassName("calendar")[0];
Get the iFrame inside:
var iFrame = calendarDiv.getElementsByTagName("iframe")[0];
set an attribute:
iFrame.setAttribute("frameborder", "0");
Or, since getElementsByClassName isn't supported in old versions of IE, consider setting the id on the iFrame and simply doing:
document.getElementById("iFrameId").setAttribute("frameborder", "0");
First of all, you need to give your iframe id.
After that, you can get your iframe with the function document.getElementById(""), and than to change it's property.
For example:
<html>
<body>
<div class="calendar">
<iframe id="myIframe"></iframe>
</div>
<script type="text/javascript">
document.getElementById("myIframe").frameborder = 1;
</script>
</body>
</html>
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