我正在尝试使用JavaScript添加一系列<p<a/a>/p>元素,并希望使用JavaScript更改链接的活动颜色。我该如何做?我不能在CSS文件中使用a:active更改所有超链接的颜色,因为我有一组其他链接,我想要不同的颜色,我目前正在使用CSS来解决这个问题。
以下是我的JavaScript添加内容:
以下是我的JavaScript添加内容:
var supertag = document.createElement("p");
var tag = document.createElement('a');
var text = document.createTextNode("Join a New Community!");
tag.appendChild(text);
tag.href = "http://localhost:8088/communities_index/communities_index.html";
tag.style.color = "blue";
supertag.appendChild(tag);
var element = document.getElementById("globalCommunities");
element.appendChild(tag);
我可以将超链接的颜色更改为蓝色,但这样就会失去其活动颜色(本来应该是红色)到css。其他链接是黑色的,在悬停时变成蓝色,在活动时变成红色。我希望新的超链接是蓝色的,并在活动时变成红色。