Javascript Chrome扩展:Youtube中的内容脚本(jQuery)无法正常工作

Javascript Chrome扩展:Youtube中的内容脚本(jQuery)无法正常工作,javascript,google-chrome,mouseover,Javascript,Google Chrome,Mouseover,我有这个: $(document).ready(function() { $("button.yt-uix-expander-arrow").attr("id", "yt-uix-expander-arrow"); $("#yt-uix-expander-arrow").mouseover(function() { alert("Hello"); }); }); 注入Youtube。使用右键单击>检查元素,成功地向其添加了一个id=“yt uix exp

我有这个:

$(document).ready(function() {
    $("button.yt-uix-expander-arrow").attr("id", "yt-uix-expander-arrow");
    $("#yt-uix-expander-arrow").mouseover(function() {
        alert("Hello");
    });
});
注入Youtube。使用右键单击>检查元素,
成功地向其添加了一个
id=“yt uix expander arrow”
属性。但是,不会触发鼠标悬停事件。但是,如果我将
$(“#yt uix expander arrow”).mouseover()
更改为
$(“.yt uix expander arrow”).mouseover()
,它会起作用

这很不寻常,因为#yt uix expander arrow id已经添加到按钮元素中。我在Facebook上对它进行了测试,在类中添加了一个id,并在id上执行了mouseover()事件,它成功了


有什么想法吗?

你能提供更多信息吗?你到底想做什么(我的意思是比显而易见的要多)?您能否以更易于测试的形式提供代码(即提供内容脚本或至少提供您试图使用此代码的页面的url以及内容脚本的摘要)

你有没有试着把他们锁在一起

$("button.yt-uix-expander-arrow").attr("id", "yt-uix-expander-arrow").mouseover(
    function() {
        alert("Hello");
    }
 );

我设置了最好的测试,你的代码运行得很好(我想,我也不确定你到底想做什么)。如果没有更多的上下文,很难说出问题所在。

嗨,谢谢,我已经知道了。我很粗心,有两个按钮具有相同的类,我将id添加到了这两个按钮中。那当然不行。无论如何,您可以在这里找到我的分机: