Jump to content
Sign in to follow this  
vj5

highlight link

Recommended Posts

I want to change the color of the link when clicked on it. How do I do it? I tried giving vlink , alink attribute but still it doesn't work. can someone please help?

Share this post


Link to post
Share on other sites

There is no such thing as alink or vlink attributed.You can use CSS to choose how a link looks after it's clicked:a:link {/* A normal link */color: blue;}a:visited {/* A visited link */color: purple;}a:hover {/* The mouse is over the link */color: #0099FF;}a:active {/* The mouse button is pressed on the link */color: red;}

Share this post


Link to post
Share on other sites

Hi, i would try something like this:

<a onclick="changeColor(this)" >take me there</a>in js:function changeColor(link){  link.style.color = "#FFFFFF";}

of course it would be better to have all the js inobtrusive, but ...

Share this post


Link to post
Share on other sites
There is no such thing as alink or vlink attributed.You can use CSS to choose how a link looks after it's clicked:a:link {/* A normal link */color: blue;}a:visited {/* A visited link */color: purple;}a:hover {/* The mouse is over the link */color: #0099FF;}a:active {/* The mouse button is pressed on the link */color: red;}
Instead of CSS , I gave it in the body of the page. Anyway, I want to change the color of the link when clicked and stay that color. Is it possible to do so?

Share this post


Link to post
Share on other sites

Yes, your question has been answered already by alexnofue.If you want to apply it to all the links of the document at once, you can have a code like this in the head of your document:

<script type="text/javascript">function changeColor(e) {  e = (e)?e:window.event;  e = (e.nodeType == 3)?e.parentNode:e;  link = (e.srcElement)e.srcElement:e.target;  link.style.color = "#FFFFFF";}window.onload = function() {  var A = document.getElementsByTagName("a");  for (var i=0;i<A.length;i++) {	A[i].onclick = changeColor;  }}</script>

Share this post


Link to post
Share on other sites
Yes, your question has been answered already by alexnofue.If you want to apply it to all the links of the document at once, you can have a code like this in the head of your document:
<script type="text/javascript">function changeColor(e) {  e = (e)?e:window.event;  e = (e.nodeType == 3)?e.parentNode:e;  link = (e.srcElement)e.srcElement:e.target;  link.style.color = "#FFFFFF";}window.onload = function() {  var A = document.getElementsByTagName("a");  for (var i=0;i<A.length;i++) {	A[i].onclick = changeColor;  }}</script>

I copied your code to my page. It gives errors. Its says that it needs an ; somewhere in the code. Right now, it is not doing anything.

Share this post


Link to post
Share on other sites
Hi, i would try something like this:
<a onclick="changeColor(this)" >take me there</a>in js:function changeColor(link){  link.style.color = "#FFFFFF";}

of course it would be better to have all the js inobtrusive, but ...

You code does only when clicked on the link, it shows the color then it goes off. I want the color to change .

Share this post


Link to post
Share on other sites

I fixed the error. When clicked on the link, it shows the color, then the color goes off. I want the color to be there , ie, changed. I am creating headers and each link is taking the user to a page. For example, if I have blue links, when click on it, it should turn red and stay red so it is understood that I am on that page.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...