Search code examples
javascriptautorotate

Javascript function only working on single post


i am trying to do is automatically rotate a ads on my sidebar using this javascript.

function run() {
    var prev = $("#pengiklanan a.beriklan:first-child");
    $.unique(prev).each(function(i) {
      $(this).delay(i*1000).slideUp(function() {
        $(this).appendTo(this.parentNode).slideDown();
      });
    });
}

window.setInterval(run,19000);

AND my ads source on my sidebar is

<div id="pengiklanan"><a href="https://www.facebook.com/messages/BelajarSeo" target="_blank" class="beriklan"><h6 class="ohiklan">Iklan Anda</h6><p><em>cepat, ruangan terhad</em></p></a>
<a href="https://www.facebook.com/messages/BelajarSeo" target="_blank" class="beriklan"><h6 class="ohiklan">Iklan Anda</h6><p><em>cepat, ruangan terhad</em></p></a>
<a href="https://www.facebook.com/messages/BelajarSeo" target="_blank" class="beriklan"><h6 class="ohiklan">Iklan Anda</h6><p><em>cepat, ruangan terhad</em></p></a>
<a href="https://www.facebook.com/messages/BelajarSeo" target="_blank" class="beriklan"><h6 class="ohiklan">Iklan Anda</h6><p><em>cepat, ruangan terhad</em></p></a>
<a href="https://www.facebook.com/messages/BelajarSeo" target="_blank" class="beriklan"><h6 class="ohiklan">Iklan Anda</h6><p><em>cepat, ruangan terhad</em></p></a>
<a href="https://www.facebook.com/messages/BelajarSeo" target="_blank" class="beriklan"><h6 class="ohiklan">Iklan Anda</h6><p><em>cepat, ruangan terhad</em></p></a>
<a href="https://www.facebook.com/messages/BelajarSeo" target="_blank" class="beriklan"><h6 class="ohiklan">Iklan Anda</h6><p><em>cepat, ruangan terhad</em></p></a></div>

This javascript function is working (rotate a ads on my sidebar) on my single post. But in my homepage, page, category, tags and other page, this javascript not working.

Anyone please... - my site


Solution

  • One of the scripts on your page calls a function jQuery.noConflict();. This means that you no longer can reference jQuery by $ to avoid conflicts with some other script.

    So you either need to remove that line, but most probably there's a good reason it's there. Or you can replace all your references to $ by jQuery.

    I found this using Firebug, which tells you that $ was not defined. You just needed to know why it wasn't from there.