function linksSwap() {
document.getElementById("left").style.display = "none";
document.getElementById("right").style.display = "table-row";
}
function rechtsSwap() {
document.getElementById("right").style.display = "none";
document.getElementById("left").style.display = "table-row";
}
<ul>
<li><a onclick="linksSwap()" href="#">Left</a></li>
<li><a onclick="rechtsSwap()" href="#">Right</a></li>
</ul>
<div class="tabel">
<table class="tg" id="eersteTabel">
<tbody>
<tr id="right">
<td class="tg-1h1z">Coca Cola 1 </td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
<tr id="right">
<td class="tg-1h1z">Coca Cola Zero 2</td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
<tr id="right">
<td class="tg-1h1z">Coca Cola Light 3</td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
<tr id="left">
<td class="tg-1h1z">Fïnley Bitter Lemon 4 </td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
<tr id="left">
<td class="tg-1h1z">Cassis 5</td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
</tbody>
</table>
</div>
I made a code where I have this table which I want to order [Left | Right] I hoped the javascript would target all the ID's. Instead of only one. (I left out CSS because its not important)
I added numbers to make it a bit more clear,
What is happening: Pressing Left: 1235 Pressing Right: 2345
What I want: Left: 45 Right: 123
Is there another way to fix this instead of using a forloop?
Add working code since topic is closed.
function linksSwap() {
document.querySelectorAll(".left").forEach(function(e){e.style.display = "none"})
document.querySelectorAll(".right").forEach(function(e){e.style.display = "table-row"})
}
function rechtsSwap() {
document.querySelectorAll(".left").forEach(function(e){e.style.display = "table-row"})
document.querySelectorAll(".right").forEach(function(e){e.style.display = "none"})
}
<ul>
<li><a onclick="linksSwap()" href="#">Left</a></li>
<li><a onclick="rechtsSwap()" href="#">Right</a></li>
</ul>
<div class="tabel">
<table class="tg" id="eersteTabel">
<tbody>
<tr class="right">
<td class="tg-1h1z">Coca Cola 1 </td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
<tr class="right">
<td class="tg-1h1z">Coca Cola Zero 2</td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
<tr class="right">
<td class="tg-1h1z">Coca Cola Light 3</td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
<tr class="left">
<td class="tg-1h1z">Fïnley Bitter Lemon 4 </td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
<tr class="left">
<td class="tg-1h1z">Cassis 5</td>
<td class="tg-utt9">
<input type="tel" />
</td>
</tr>
</tbody>
</table>
</div>