Created
November 14, 2013 13:58
-
-
Save richcahill/7467223 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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