I'm using jstree and I want to delete a specific node by its ID after a click on a button.
This is my tree in html list format:
<div id="testtree">
<ul>
<li id="1" title="ID:1"><a>Fruits and Vegetables</a>
<ul>
<li id="11" title="ID:11"><a>Fruit</a>
<ul>
<li id="111" title="ID:111"><a>Apple</a></li>
<li id="112" title="ID:112"><a>Banana</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
and this is my button event (I've got several buttons, hence the array):
buttons[0].addEventListener( "click", function( ev ) {
$("#testtree").jstree("remove", $("111"));
});
Any ideas what I'm missing?
Update:
I've corrected the typo but it still doesn't work. Here's the complete code, maybe the mistake is somewhere else?
<html>
<head>
<title>jstree test</title>
</head>
<body>
<div id="testtree">
<ul>
<li id="1" title="ID:1"><a>Fruits and Vegetables</a>
<ul>
<li id="11" title="ID:11"><a>Fruit</a>
<ul>
<li id="111" title="ID:111"><a>Apple</a></li>
<li id="112" title="ID:112"><a>Banana</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<button>Remove Apple</button>
<script type="text/javascript" src="_lib/jquery.js"></script>
<script type="text/javascript" src="jquery.jstree.js"></script>
<script>
$(document).ready(function() {
$("#testtree").jstree({
"plugins" : [ "themes", "html_data", "checkbox", "ui" ],
"core": { "initially_open": ["1"]}
});
});
var buttons = document.querySelectorAll("button");
buttons[0].addEventListener( "click", function( ev ) {
$("#testtree").jstree("remove","#111");
});
</script>
</body>
</html>