开发者

Using jQuery plugins in greasemonkey (i.e. tipsy)

开发者 https://www.devze.com 2023-01-29 06:31 出处:网络
I\'m trying (and for the most part succeeding) to use the tipsy jQuery plugin in my greasemonkey script. I am using the @require meta tag to import the jquery and tipsy js, and it works, but with a co

I'm trying (and for the most part succeeding) to use the tipsy jQuery plugin in my greasemonkey script. I am using the @require meta tag to import the jquery and tipsy js, and it works, but with a couple caveats which I'm trying to overcome.

Accessing elements as a pure jQuery object fails开发者_JS百科, so I'm relegated to using DOM functions to get my elements:

//this fails
$('#login').find('a:first').tipsy(); 

//while this succeeds
$(document.getElementById('login').getElementsByTagName('a')[0]).tipsy();

Anyone know why? Need more info? TIA!


I think it's because inside Greasemonkey, jQuery has a different default context than the document. Try this:

$("#login", document).find('a:first').tipsy();
0

精彩评论

暂无评论...
验证码 换一张
取 消