views:

472

answers:

2

I am using a jQuery ticker which is pretty cool. It works well with predefined content, but I want to build my tags dynamically by getting the data from a feed via the $.ajax method.

http://progadv.uuuq.com/jStockTicker/

The problem is when I do this the ticker wont work, as it looks like the function might be loading before my page content has loaded. Can anbody think of a way around this?

$(function() {
    $("#ticker").jStockTicker({interval: 45});
});
A: 
$(document).ready(function() {
 $("#ticker").jStockTicker({interval: 45});
});
Glennular
unfortunately that doesn't work. I get an error:" $ticker.children().get(0) is undefined "I am loading the actual ticker content in a body onLoad event. Is it possible I am getting the error because of this?
Dkong
if you are loading the content in the onLoad, why don't you call jStockTicker at that time?
Glennular
i tried that but still no joy :(
Dkong
perhaps more code might be needed for us to help you.
Glennular
A: 

You need to call the jStockTicker function from within the success method with the Ajax call, because like you say, jStockTicker is calculating the dimensions for scrolling before the content has been added to the page.

$.ajax({
    url: 'ajax/test.html',
    success: function(data) {
      //Populate $('#ticker') with data here, e.g...
      $('#ticker').html(data);

      //Now call jStockTicker
      $("#ticker").jStockTicker({interval: 45});
    }
  });

Something like that ought to do it.

Rich

purpletonic