app.js
function alterarStatus(idDoItem)
{
if(verificarEstadoDoItem(idDoItem))
{
//muda para devolver
definirEstadoDoItem(idDoItem, 'dashboard__item__img dashboard__item__img--rented', 'dashboard__item__button dashboard__item__button--return', 'Devolver');
}
else
{
//muda para alugar
definirEstadoDoItem(idDoItem, 'dashboard__item__img', 'dashboard__item__button', 'Alugar');
}
}
function verificarEstadoDoItem(idDoItem)
{
return 'dashboard__item__img' == document.getElementById(`capa-${idDoItem}`).getAttribute('class') && 'dashboard__item__button' == document.getElementById(`botao-${idDoItem}`).getAttribute('class') && 'Alugar' == document.getElementById(`botao-${idDoItem}`).textContent;
}
function definirEstadoDoItem(idDoItem, estadoDaCapa, estadoDoBotao, textoDoBotao)
{
document.getElementById(`capa-${idDoItem}`).setAttribute('class', estadoDaCapa);
document.getElementById(`botao-${idDoItem}`).setAttribute('class', estadoDoBotao);
document.getElementById(`botao-${idDoItem}`).textContent = textoDoBotao;
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AluGames</title>
<link rel="stylesheet" href="css/main.css">
</head>
<body class="body">
<main class="container main">
<img src="img/logo.svg" alt="Logo AluGames">
<section class="divisor">
<div class="divisor__line"></div>
<img src="img/fade_bar.svg" alt="Visual bar" class="divisor__bar">
<div class="divisor__line"></div>
</section>
<h1 class="page-title">Aluguel de <span class="page-title__emphasis">boardgames</span></h1>
<section class="dashboard">
<ul class="dashboard__items">
<li class="dashboard__items__item" id="game-1">
<div class="dashboard__item__img" id="capa-1">
<img src="img/monopoly.png" alt="Capa jogo Monopoly">
</div>
<p class="dashboard__item__name">Monopoly</p>
<a onclick="alterarStatus(1)" href="#" class="dashboard__item__button" id="botao-1">Alugar</a>
</li>
<li class="dashboard__items__item" id="game-2">
<div class="dashboard__item__img" id="capa-2">
<img src="img/ticket_to_ride.png" alt="Capa jogo Ticket to Ride">
</div>
<p class="dashboard__item__name">Ticket to Ride</p>
<a onclick="alterarStatus(2)" href="#" class="dashboard__item__button" id="botao-2">Alugar</a>
</li>
<li class="dashboard__items__item" id="game-3">
<div class="dashboard__item__img" id="capa-3">
<img src="img/takenoko.png" alt="Capa jogo Takenoko">
</div>
<p class="dashboard__item__name">Takenoko</p>
<a onclick="alterarStatus(3)" href="#" class="dashboard__item__button" id="botao-3">Alugar</a>
</li>
</ul>
</section>
<img src="img/hachuras.svg" alt="Visual hachuras" class="hachuras">
</main>
<script src="js/app.js"></script>
</body>
</html>