I encountered an issue while using a script to toggle a div on click. Strangely, the content of the div failed to display properly on mobile devices such as Android and iOS. Despite my attempts to troubleshoot the problem, I was unable to identify the cause. Surprisingly, the implementation worked perfectly fine on desktop browsers like Safari and Chrome.
Snippet of My Script
var toggle = function() {
var mydiv = document.getElementById('newpost');
if (mydiv.style.display === 'none' || mydiv.style.display === '')
mydiv.style.display = 'block';
else
mydiv.style.display = 'none'
}
My HTML Code
<div id="newpost">
CONTENT
</div>
<input type="submit" class="btn btn-primary" style ="width: 100%; margin-bottom: 20px" value="Click here" onclick="this.style.display='none';toggle();" alt="Click here">
</input>
==
Solution Found
The root cause of the issue was traced back to a CSS animation that was incompatible with mobile devices. By eliminating the animation effects altogether, I successfully resolved the problem and restored functionality across all platforms!