Thursday, 15 September 2011

javascript - Inserting variable (grabbed from json) into element -



javascript - Inserting variable (grabbed from json) into element -

i have function grab video title youtube json callback, works - i'm having issues inserting variable element.

here feed i'm grabbing:

<script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos/2wnrx2jq184?v=2&amp;alt=json-in-script&amp;callback=youtubefeedcallback"></script>

the javascript function i'm using:

function youtubefeedcallback(data) { var info = data.entry.title.$t; document.write(info); }

this works fine, i'd insert div id "box".

usually utilize next (and add together function - , remove document.write):

var box = document.getelementbyid('box'); box.innerhtml = info;

i cannot work though. right way accomplish i'm trying do? thanks

http://jsfiddle.net/b3vyt/

either create sure script below element or wrap code in document.ready callback not run until after dom loaded.

http://jsfiddle.net/b3vyt/1

javascript json variables callback youtube

No comments:

Post a Comment