1
I have a problem, I have a list and when the user clicks it adds the id of this <li>
in an array, but I want when it click again on that <li>
, this id is removed from id.
Here it is in the JSFIDDLE.
HTML:
<ul>
<li id="1">Teste 1</li>
<li id="2">Teste 2</li>
<li id="3">Teste 3</li>
<li id="4">Teste 4</li>
<li id="5">Teste 5</li>
<li id="6">Teste 6</li>
<li id="7">Teste 7</li>
<li id="8">Teste 8</li>
<li id="9">Teste 9</li>
<li id="10">Teste 10</li>
</ul>
<a href="#" id="show">Exibir selecionados</a>
<div id="retorno"></div>
Javascript
$(function(){
var idsSelecionados = [];
$('li').click(function(){
var id = $(this).attr('id');
idsSelecionados.push(id+',');
$(this).toggleClass("active");
});
$('#show').on('click', function(){
$.each(idsSelecionados, function(i, val){
$('#retorno').append(val);
});
});
});