Looking for a solution to dynamically resize a div in JavaScript when clicking on a link element (<a>
). However, the code doesn't seem to function properly on my iPhone.
Let's start with a basic link:
<a href="#" onfocus="menu()">MENU</a>
When this link is clicked, it expands a specific div to fill the screen and displays content. Inside that div, there's another link to close the expanded area:
<a href="#" onfocus="revert()">close</a>
Here's the corresponding JavaScript code:
<script>
var headerHeight = document.getElementById("header_container").clientHeight;
function menu() {
document.getElementById("nav_container").style = "display:block;";
document.getElementById("header_container").style = "height:100%";
document.getElementById("header").style = "height:100%";
}
function revert(){
document.getElementById("nav_container").style = "display:none;";
document.getElementById("header_container").style = "height:"+headerHeight+";";
document.getElementById("header").style = "height:"+headerHeight+";";
}
</script>
Although this code works perfectly on desktop browsers like Firefox Developer Edition in responsive design mode with touch events simulated, it fails to perform as expected on my mobile device 😞
Upon clicking the button, nothing happens. Any suggestions or insights on how to resolve this issue?