I can't seem to figure out why the toggle doesn't work after my ajax xml load. It pulls the xml correctly. However, fails to execute the toggle.
Here is the jQuery onclick both xml load and toggle
$("document").ready(function(){
$("#demo").on("click", loadxml);
$("#demo-2").click(function(){
$("li").toggle("fast");
});
});
The loadxml function :
function loadxml(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if (xhttp.readyState == 4 && xhttp.status == 200) {
myFunction (xhttp);
}
};
xhttp.open("GET","xml/categories.xml", true);
xhttp.send();
}
function myFunction(xml){
var i;
var xmlDoc = xml.responseXML;
var list = '<ul id="demo-2" class="list-unstyled no-bullet"><span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span> Categories';
var x = xmlDoc.getElementsByTagName("Categories");
for(i=0; i<x.length; i++) {
list += '<li><span class="glyphicon glyphicon-minus" aria-hidden="true"></span>' + x[i].getElementsByTagName("CategoryName")[0].childNodes[0].nodeValue + "</li>";
}
list += "</ul>"
document.getElementById("change").innerHTML = list;
}
Here is the html:
<div class="container" id="change">
<ul id="demo"></ul>
</div>