Skip to content

Instantly share code, notes, and snippets.

@richcahill
Created November 14, 2013 13:58
Show Gist options
  • Save richcahill/7467223 to your computer and use it in GitHub Desktop.
Save richcahill/7467223 to your computer and use it in GitHub Desktop.
//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