tags:

views:

29

answers:

2
function appendRefToLinks(ref){
    alert("hi");
        $j('a').each(function(i){
            alert('hello');
            $j(this).attr('href',$j(this).attr('href') + "?ref=" + $j.cookie.get("tb_ref"));
        }); 
}

I see the hi alert, but I have to links on my page, and I never see hello.... what am I doing wrong?

+2  A: 

Did all the links rendered before you call the function?

You should use .click instead.

You can use .live so dynamic inserted links would also get the function.

BrunoLM
+2  A: 

You're probably calling the function before the page is parsed.

You need to wrap the code that calls it in $j(function() { ... }); so that it executes after the browser loads the page.

SLaks