I am working on an php page that adds an li element on button click that is sortable due to jquery. What I am having an issue with is closing/removing that li element. Below is what I am using:
What is occurring is all the li elements are removed from the page and all I would like is the parent li to be removed.
I have checked around but couldn't find anything to resolve the issue.
Jquery Remove | Delete Parent | Remove Parent
I believe this has to do with my jquery but I can't find out where.
$(function() {
$("#sortable").sortable();
$("#sortable").disableSelection();
});
$(document).ready(function() {
$("#button").click(function() {
$("#sortable").append('<li class="ui-state-default"><div id="menu" style="position: relative; margin-top:3px; font-size:25px; width:100%; height:30px;"><a id="close" href="" class="close">x</a><div id="box-name">Test 1</div></div></div></li>');
});
});
$(document).on('click', '.close', function() {
$(this).parent('.ui-state-default').remove();
//$(this).closest('.ui-state-default').fadeOut(300);
});
#sortable {
list-style-type: none;
margin: 0;
padding: 0;
width: 300px;
height: 120px;
}
#sortable li {
margin: 1%;
float: left;
width: 23.00%;
height: 97.5%;
font-size: 4em;
text-align: center;
background-color: #fff;
border-radius: 4px;
box-shadow: 0 0 12px .5px #000;
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<script>
</script>
<body>
<div id="">
<!-- button to add li -->
<input type="button" id="button" value="Click me">
</div>
<div class="data">
<!-- Container div -->
<ul id="sortable">
<!-- beginning of sortable list -->
<li class="ui-state-default">
<!-- li class that is duplicated -->
<div id="menu" style="position: relative; margin-top:3px; font-size:25px; width:100%; height:30px;">
<a class="close" id="close" href="">
<!-- a tag to close li -->
x
</a>
<div id="box-name">Test 1</div>
</div>
</div>
</li>
</ul>
</div>
</body>
</html>