7
I’m having problems with the code below. In case I have two menus, the menu menuAprendido
and the menu menuAprender
and I have to add objects to menuAprender
and move them to the menuAprendido
, so far so good. The problem is that by clicking the move button, I can add the item to the menuAprendido
but I don’t know how to remove it from the menuAprender
and ,consequently, do not know how, by pressing the remove button, remove some specific item from the menuAprender
.
I know there’s a command $('algumacoisa').remove();
, but I couldn’t use it to delete a specific object from the menu.
/**
* Created by Erick on 24/10/2014.
*/
$(document).ready(function() {
var array = new Array();
$("#okbtn").click(function() {
var item = $(".inputTema").val();
if(item == "") return;
item = "<div class='list-group-item' align='center'>" + item + "</div>";
array.push(item);
$("#menuAprender").append(item);
confirm('Assunto adicionado com sucesso');
});
$("#moverbtn").click(function() {
var assunto = prompt('digite o assunto que deseja mover para a lista de assuntos que já aprendeu!');
if(assunto == "") return;
assunto = "<div class='list-group-item' align='center'>" + assunto + "</div>";
for(var i = 0; i < array.length; i++) {
var j = ("#" + i).val();
if(assunto === array[i]) {
$("#menuAprendido").append(assunto);
confirm('Assunto movido com sucesso');
}
}
});
$("#removerbtn").click(function() {
var assunto = prompt('digite o assunto que deseja remover da lista de assuntos que deseja aprender!');
if(item == "") return;
assunto = "<div class='list-group-item' align='center'>" + assunto + "</div>";
for(var i = 0; i < array.length; i++) {
if(assunto === array[i]) {
confirm('Assunto removido com sucesso');
}
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SI1</title>
<link rel="stylesheet" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/script_pagina3.js"></script>
<style>
#one {
width: 500px;
}
#two {
width: 500px;
}
</style>
</head>
<body>
<div class="jumbotron">
<div class="container">
<h1>Sistemas de Informação 1</h1>
<p>Obrigado por ter se cadastrado na disciplina.</p>
</div>
</div>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title" align="center">Caso deseje você pode nos mostrar o que deseja aprender ou já aprendeu.</h2>
</div>
<div class="panel-body">
<div class="container" id="one">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title" align="center">Assuntos que eu gostaria de aprender.</h2>
<br>
<div align="center"><input type="text" class="inputTema"><button type="submit" id="okbtn">OK</button></div>
</div>
<div class="panel-body">
<div id="menuAprender">
</div>
</div>
</div>
</div>
<div align="center">
<button type="submit" id="moverbtn">mover</button>
<button type="submit" id="removerbtn">remover</button>
</div>
<div class="panel-body">
<div class="container" id="two">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title" align="center">Assuntos que já aprendi.</h2>
</div>
<div class="panel-body">
<div id="menuAprendido">
</div>
</div>
</div>
</div>
<div class="panel-body">
<div align="center">
<a href="index.html">
<button type="submit">Voltar para a página inicial</button>
</a>
</div>
</div>
</div>
</div>
</body>
</html>
Dude helped a lot, thank you very much. I only have doubts now about remove(), as I cannot remove a specific element when I click the remove button
– Erick
@Erick I updated the response with the removal code (the principles are the same).
– bfavaretto
@bfavaretto I’ve been editing the code these days and did some tests, I realized that if I add two subjects like "Si" and "Si2" (information systems), and try to move the subject "Si" it will move both. I tried to fix it but I didn’t succeed.
– Erick
@Erick I added the correction of that.
– bfavaretto