I have five anchor tags. I want to display second anchor tag on click of first anchor tag and hide it self and further when click on second anchor tag show third anchor tag and hide itself and so on.
<a href="javascript:void(0)" id="btn0" onclick='showBtn1()' class="w-auto rounded-pill bg-transparent border px-3 py-2 text-decoration-none text-reset suggestion"><?php print(strval($suggestions[0])); ?></a>
<a href="javascript:void(0)" id="btn1" style="display:none" class="w-auto rounded-pill bg-transparent border px-3 py-2 text-decoration-none text-reset suggestion"><?php print(strval($suggestions[1])); ?></a>
<a href="javascript:void(0)" id="btn2" style="display:none" class="w-auto rounded-pill bg-transparent border px-3 py-2 text-decoration-none text-reset suggestion"><?php print(strval($suggestions[2])); ?></a>
<a href="javascript:void(0)" id="btn3" style="display:none" class="w-auto rounded-pill bg-transparent border px-3 py-2 text-decoration-none text-reset suggestion"><?php print(strval($suggestions[3])); ?></a>
<a href="javascript:void(0)" id="btn4" style="display:none" class="w-auto rounded-pill bg-transparent border px-3 py-2 text-decoration-none text-reset suggestion"><?php print(strval($suggestions[4])); ?></a>
<script>
function showBtn1()
{
var btn0 = document.getElementById('btn0');
var btn1 = document.getElementById('btn1');
var btn2 = document.getElementById('btn2');
var btn3 = document.getElementById('btn3');
var btn4 = document.getElementById('btn4');
if(btn1.style.display == 'none')
{
btn1.style.display = 'initial';
btn0.style.display = 'none';
btn2.style.display = 'none';
btn3.style.display = 'none';
btn4.style.display = 'none';
}
else
{
btn1.style.display = 'none';
btn0.style.display = 'none';
btn2.style.display = 'none';
btn3.style.display = 'none';
btn4.style.display = 'none';
}
}
</script>
Here you go:
In the buttons use
onclick='showBtn(1 up to 5)'Have fun learning. Read a little about coding principles.