I'm basically adding an iframe inside my "panel" class. I want the iframe to display when the button has been clicked on and if its clicked on again, hide it. How would i go abouts doing this?
This is the html code for my accordion:
<button class="accordion">Link1</button>
<div class="panel">
<iframe src="linkcodehere" class="iframestreet" style="border:0; display:none; visibility: hidden;"></iframe>
//some other code to display information
</div>
<button class="accordion">Link2</button>
<div class="panel">
<iframe src="linkcodehere2" class="iframestreet" style="border:0; display:none; visibility: hidden;"></iframe>
//some other code to display information
</div>
This is the code for the javascript to display elements inside class panel:
$(document).ready(function() {
var acc = document.getElementsByClassName("accordion");
var i;
var id = document.getElementsByClassName("iframestreet");
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
if (id[i].style.display == 'block'){
console.log("hide this");
id[i].style.display = 'none';
id[i].style.visibility = 'hidden';
} else {
console.log("display it");
id[i].style.display = 'block';
id[i].style.visibility = 'visible';
}
}
}
});
I'm getting this error when I look into my console log: Uncaught TypeError: Cannot read property 'style' of undefined