javascript - Different link color on different html pages using the same css doc -


i'm new programming, apologize is, i'm sure, relatively simple question.

i'm looking efficient way make link color within <a> tags of each html page different (i.e. 1 page have green links, while have blue links) without having add class="green" or class="blue" every single <a> tag.

i understand have separate css documents each page, i'd keep whole site on 1 css page, don't have update each style sheet separately when want make overarching changes.

is there way of defining style rules in <a> tags in relation class of higher tag? example, possible say

<body> <div class="page1content"> <p>text here  <a href="someurl.com"> link here </a>  more text  <a href="secondurl.com"> second link</p>  </div>  <div class="footer"> <p>even more text <a href="thirdurl.com"></a></p> </div> </body> 

and define first 2 <a> tags (without affecting third <a> tag) in relation <div class="page1content">? i'd replace <div class="page2">, <div class="page3">, etc. each page.

the other thing think of try using javascript, i'm not familiar. tried inserting

<script type="text/javascript"> var myobj = document.getelementsbytagname("a"); myobj.style.color="green"; </script> 

into given page, hoping make text color within <a> tags on page green, didn't seem work.

by way of comparison, tested javascript changing "a" "p" follows:

<script type="text/javascript"> var myobj = document.getelementsbytagname("p"); myobj.style.color="green"; </script> 

in hope turn <p> text green, didn't work either, miscoded javascript, starters.

any thoughts on how alter multiple <a> tags on given page @ once (without putting class inside tag) appreciated.

thanks!

give each body element id, select descendent anchor tag element in css:

body#mybody1 {color: red;}  body#mybody2 {color: blue;} 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -