P粉2327937652023-09-06 21:48:27
Changed code (working)
<section> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-3 col-xl-3"> <a href="#" id="text-1" onclick="showText('text-1')"> <div class="home-side-menu">Mission Statement</div> </a> <a href="#" id="text-2" onclick="showText('text-2')"> <div class="home-side-menu">Letter-writing</div> </a> <a href="#" id="text-3" onclick="showText('text-3')"> <div class="home-side-menu">Peace Ideas</div> </a> <a href="#" id="text-4" onclick="showText('text-4')"> <div class="home-side-menu">Power Of Love</div> </a> </div> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-9 col-xl-9"> <div class="text-formatting" id="new-text"> </div> </div> </div> </section> <script type="text/javascript"> function showText(id) { if (id === "text-1") document.getElementById('new-text').innerHTML = "SAMPLE TEXT 1"; if (id === "text-2") document.getElementById('new-text').innerHTML = "SAMPLE TEXT 2"; if (id === "text-3") document.getElementById('new-text').innerHTML = "SAMPLE TEXT 3"; if (id === "text-4") document.getElementById('new-text').innerHTML = "SAMPLE TEXT 4"; } </script>
Inside onclick="show-text()
, pass a valid parameter (matching your IF condition), such as "text-1" or "text-2"..
And use ===
(strict equality check) in Script for comparison. CheckJs comparison operators