Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//you need this first bit for all jquery code
$(document).ready(function(){
// Click on an a tag with class="studio"
$(".studio").click(function(){
// Assign variable studioName to the attribute "data-name" in the a tag. Convert it to text
var studioName = $(this).attr('data-name');
// Get the json
$.ajax({
url:'database.json'
}).done(function(data){
$.each(data.studios,function(index,value){
if(studioName == value.name){
//Replace each of the divs with text from different parts of the json
$("#name").text(value.name);
$("#location").text(value.location);
$("#founded").text(value.founded);
$("#website").text(value.website);
$("#website").attr('href', value.website);
$("#phone").text(value.phone);
$("#description").text(value.description);
$("#logo").attr("src", value.logo);
$("#featuredimg").attr("src", value.image);
return;
}
});
//if your code echoes this, the name was not in your data (fail safe)
console.log("sorry, that item wasn't in the list");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.