This code snippet is designed to be responsive and work effectively on both mobile devices and desktops:
<div class='main'>
<button id='mainbtn'>
Click me
</button>
<div class='btns' id='pcbtn' style='display:none;'>
<button id='1'>
Option 1
</button>
<button id='2'>
Option 2
</button>
<button id='3'>
Option 3
</button>
</div>
<div id='mobbtn' style='display:none'>
<li>
<ul>
<button id='1'>
Sub-option 1
</button>
</ul>
<ul>
<button id='2'>
Sub-option 2
</button>
</ul>
<ul>
<button id='3'>
Sub-option 3
</button>
</ul>
</li>
</div>
</div>
<script>
document.getElementById('mainbtn').onclick = () => {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
document.getElementById('mobbtn').style.display = 'block';
} else {
document.getElementById('pcbtn').style.display = 'flex';
}
}
</script>
In this implementation, there is a main container div with two nested divs - one catering to desktop users and the other to mobile users. The buttons within these divs are initially hidden, but upon triggering the main button, the appropriate set of buttons will be displayed based on the device being used.