jQuery: something is wrong with how this loop is being done
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 ale开发者_如何学运维rt, but I have to links on my page, and I never see hello.... what am I doing wrong?
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.
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.
精彩评论