views:

99

answers:

1

This is a javascript question. The fact that it mentions this website is irrelevant. This does not belong on meta.


I'm working on a Greasemonkey script to auto-load additional pages of answers onto the first page of answers here at Stackoverflow as you scroll. This is working well. I want to maintain the ability to up-vote/down-vote the loaded items, so I'm using $.live(), which is also working fine.

My problem is that the vote-object, used by SO, is not found within the scope of the $.live() method, or atleast I think that is the problem.

$(".vote-up").live("click", function(D){
  vote.up($(D.target));
});

$.get("/questions/1151074", function(data){
  $("div.answer", data).insertAfter(".answer:last");
});

That's bit of sample code you can paste into your firebug console to test. You can see that vote, in the context of the .live() call is not accessible. How can I fix this?

+1  A: 

Try unsafeWindow.vote.up().

See the docs. It's a security measure of sorts. Annoying when you forget though.

Crescent Fresh