Javascript 如何更改由破折号分隔的两个单词属性?

Javascript 如何更改由破折号分隔的两个单词属性?,javascript,html,Javascript,Html,如何使用JavaScript更改html中的两个单词属性? 示例:有一个示例HTML页面: <!DOCTYPE html> <html> <head> <script src="randomscript.js"></script> </head> <body> <h1 id="mywords" aria-label="Yellow">Words&

如何使用JavaScript更改html中的两个单词属性? 示例:有一个示例HTML页面:

<!DOCTYPE html>
<html>
    <head>
        <script src="randomscript.js"></script>
    </head>
    <body>
        <h1 id="mywords" aria-label="Yellow">Words</h1>
    </body>
</html>
但这似乎不起作用,因为
aria标签仍然是
Yellow

我该怎么做? 谢谢

编辑:根据我的文本编辑器,
aria
变为蓝色,
-
变为红色,但
标签保持白色。这表明破折号或破折号后面的东西是导致问题的原因。

请改用这个

document.querySelector("#mywords h1").setAttribute("aria-label", "Blue");
或使用jquery:

$("#mywords h1").attr("aria-label", "Blue");

编辑:我的错,没有注意到您只需要javascript。

破折号是一个减法运算符。下次,请在询问之前进行搜索。谷歌搜索“JavaScript set attribute”会给你很多答案。
$("#mywords h1").attr("aria-label", "Blue");