Guys help when i choose for example lenovo and click button it creates okey,but then i choose acer and click again to the button it creates again lenovo then acer (for example : first step (Acer) second step (Acer Acer Lenovo) how to make it unique?
$(document).ready(function () {
$('.filter-values').click(function () {
let name= $(this).parent().text();
$('.button-filter').click( function(){
if($(this).parent().find('input.filter-values').prop("checked") == true){
$('.top-head').append(`<div class = '${name}'>${name}</div>`);
}
else{
$('.top-head').find(`div.${name}`).remove();
}
return false;
} )
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div style="width: 100%; background-color: bisque;" class="top-head">
</div>
<form>
<ul>
<li>Lenovo<input class="filter-values" type="checkbox"></li>
<li>HP<input class="filter-values" type="checkbox"></li>
<li>Mac<input class="filter-values" type="checkbox"></li>
<li>Sony<input class="filter-values" type="checkbox"></li>
<li>LG<input class="filter-values" type="checkbox"></li>
</ul>
<button class="button-filter">button</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="js.js"></script>
</body>
</html>