hi, gud day... i'm trying to write a program in javascript that uses .json. i already wrote one that is when i run the program, it will create a tab dynamically, using jquery, from my json data. it's already a running program but my json data is in my javascript code. what im really confused about is how to do it using a separate .json file, .js and .html.
here is my running javascript code with my json in it
here is my running javascript code with my json in it
Code:
function CreateTab(o) { var str = '<ul>'; for (var i = 0; i < o.length; i++) { str += '<li><a href="#tab' + i + '">' + o[i].title + '</a></li>'; } str += '</ul>'; for (var i = 0; i < o.length; i++) { str += '<div id="tab' + i + '">' + o[i].desc + '</div>'; } return str; } $(document).ready(function() { var json1 = [ {"title": "tab 1", "desc":"This is tab 1"}, {"title": "tab 2", "desc":"This is tab 2"} ]; $('#tabs').append(CreateTab(json1, "#tabs", true)); });
Comment