Horizontal Navigation Dropdown menu with Javascript & JSON -
Horizontal Navigation Dropdown menu with Javascript & JSON -
how dropdown appear on horizontal navigation menu? using pure js no jquery.
here code:
var xmlhttp = new xmlhttprequest(); var nav = "navigation.json"; xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { var mynav = json.parse(xmlhttp.responsetext); mainnav(mynav); } } xmlhttp.open("get", nav, true); xmlhttp.send(); function mainnav(arr) { var out = "" var i; for(i = 0; < arr.length; i++) { out += '<a href="' + arr[i].url + '">' + arr[i].display + '</a>'; } document.getelementbyid("navlinks").innerhtml = out; }
i have json file beingness called ajax. here snippet of json data.
[ { "display":"company address", "url":"", "sub":[ { "display":"2014-2015", "url":"" }, { "display":"2013-2014", "url":"" }, { "display":"2012-2013", "url":"" }, { "display":"2011-2012", "url":"" } ]
javascript json
Comments
Post a Comment