Trying to display youtube hits on a wordpress pages using Jquery

This is my first post on the forum so go easy on me if I make a balls of it.

I’m using the Avada wordpress theme and I trying to use a callback on a specific page to the youtube api to display the hit counter of a youtube video.

Read More

I’ve included the jquery.js file in header.php

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.js"></script>

and then placed the following code in the html view on the wordpress page.

$(document).ready(function() {
    var video_id='VA770wpLX-Q';

    $.getJSON('http://gdata.youtube.com/feeds/api/videos/' + video_id + '?v=2&alt=jsonc',    function(data, status, xhr) {
        $('#targetId').text(data.data.viewCount);
    });
}); </script>

<p id="targetId"></p>

I can see the callback in the console but it wont display on the page.

Any help would be greatly appreciated.

Regards,

Stephen

Related posts

Leave a Reply

1 comment