使我网站上的每个href都有不同的颜色

Pla*_*der 3 html javascript css

目前,我使用静态CSS使用看起来像下面显示的代码的东西.

#main-content > article.mh-loop-item.clearfix.post-95.post.type-post.status-publish.format-standard.has-post-thumbnail.hentry.category-singles.tag-kxngg-jxnes-italy > div > header > h3 > a {
color: blue;
}
#main-content > article.mh-loop-item.clearfix.post-93.post.type-post.status-publish.format-standard.has-post-thumbnail.hentry.category-singles.tag-aquil-eddie-guerrero > div > header > h3 > a {
color: red;
}
Run Code Online (Sandbox Code Playgroud)

并且对于每个帖子ID,它会为那些歌曲标题生成不同的颜色,因为我试图用Javascript做一些更高级的东西,或者当有某个href与某个类时,它生成一个随机的东西该链接的颜色显示为.

Sum*_*mit 7

它可以通过jquery实现,如下所示

$(document).ready(function(){
  
  $('body a').each(function(){
    var color = 'rgb(' + randomNumber() + ',' + randomNumber() + ',' + randomNumber() + ')';
    $(this).css("color", color);
  });
  
  function randomNumber(){
    return Math.floor(256*Math.random());
  }
  
});
Run Code Online (Sandbox Code Playgroud)
<a href="javascrip:void(0)">First link</a>
<a href="javascrip:void(0)">Second link</a>
<a href="javascrip:void(0)">Third link</a>
<a href="javascrip:void(0)">Fourth link</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)