<div onclick="toggleContent(this)" class="iptv"><div class="triangle"></div><b>LUZ HD</b> - 98 channels (including 32 HD channels)
<div class="iptv_price"><b><img src="img/rj45.png" class="icon_oferta"/> 51.00 zł <img src="img/radio.png" class="icon_oferta"/>71.00 zł</b></div></div>
<div style="display:none;" class="iptv_net">
<span>IPTV + 60 Mbit/s <br/> <b><img src="img/rj45.png" class="icon_oferta"/> 60.00 zł</b></span>
<span>IPTV + 100 Mbit/s <br/> <b><img src="img/rj45.png" class="icon_oferta"/> 65.00 zł</b></span>
<span>IPTV + 200 Mbit/s <br/> <b><img src="img/rj45.png" class="icon_oferta"/> 105.00 zł</b></span>
<iframe src="https://www.avios.pl/pakiety/luzhd_S.html" width="100%;" height="300">Your browser does not support iframes.</iframe>
<div><a href="/iptv.php?load=luzhd_S">View in full screen</a></div>
</div>
<div onclick="toggleContent(this)" class="iptv"><div class="triangle"></div><b>KOMFORT HD</b> - 125 channels (including 53 HD channels)
<div class="iptv_price"><b><img src="img/rj45.png" class="icon_oferta"/> 61.00 zł <img src="img/radio.png" class="icon_oferta"/>81.00 zł</b></div></div>
<div style="display:none;" class="iptv_net">
<span>IPTV + 60 Mbit/s <br/> <b><img src="img/rj45.png" class="icon_oferta"/> 70.00 zł</b></span>
<span>IPTV + 100 Mbit/s <br/> <b><img src="img/rj45.png" class="icon_oferta"/> 75.00 zł</b></span>
<span>IPTV + 200 Mbit/s <br/> <b><img src="img/rj45.png" class="icon_oferta"/> 115.00 zł</b></span>
<iframe src="https://www.avios.pl/pakiety/komforthd.html" width="100%;" height="300">Your browser does not support iframes.</iframe>
<div><a href="/iptv.php?load=komforthd">View in full screen</a></div>
</div>
<div onclick="toggleContent(this)" class="iptv"><div class="triangle"></div><b>KOMFORT+ HD</b> - 152 channels (including 69 HD channels)
<div class="iptv_price"><b><img src="img/rj45.png" class="icon_oferta"/> 71.00 zł <img src="img/radio.png" class="icon_oferta"/>91.00 zł</b></div></div>
...Continues...
I am looking to create a JavaScript function that toggles the visibility of elements when clicked by the user. The current function works, but I also want it to hide the previous element when a new one is clicked. I would appreciate any tips or guidance on how to achieve this.
function toggleContent(obj)
{
var nextObj = obj.nextSibling;
while(!nextObj.tagName) nextObj = nextObj.nextSibling;
nextObj.style.display = nextObj.style.display != 'block' ? 'block' : 'none';
}