Code is Working on Fiddle but not on Website [duplicate]

点点圈 提交于 2019-11-29 12:09:19

Your website JS code needs to wait for DOM ready before the jQuery can find the #ubaPlayer and a[rel=vidbox] elements (This is because your script is declared before the HTML, you could get away with it if your script was defined after the html, albeit not a great idea because you really should have your JavaScript in a external .js file).

So, wrap it with .ready() so that your scripts run after the DOM is ready:

   jQuery(document).ready(function () {
       jQuery("#ubaPlayer").ubaPlayer({
           codecs: [{
             name: "MP3",
             codec: 'audio/mpeg;'
           }]
       });
       jQuery('a[rel=vidbox]').click(function () {
           if (jQuery("#ubaPlayer").ubaPlayer("playing") === true) {
               jQuery("#ubaPlayer").ubaPlayer("pause");
           }
           return false;
       });

   });

The fiddle has on DOM ready, so it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!