Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

this.style.color in NS? (regarding <a>)

Status
Not open for further replies.

avivit

Technical User
Jul 5, 2000
456
IL
Could someone please tell me what's the right css code for:
this.style.color="red" in NS???
It works with ie.
this.color="red"; does not work either
I can't use id because I have a list of links, and they will all
have the same id, because the links are built from a database.
Anyone? Thanks alot in advance

part of the code:

<script language=&quot;javascript&quot;>
function linkColorOnmouseover(current)
{ if (IE)
current.style.color=&quot;red&quot;; //colors the link in red onmouseover
else if (NS)
current.color=&quot;red&quot;; //colors the link in red onmouseover
//This line does not effect using NS!!!
}
</script>
...
<body>
<a href=&quot;#&quot; onmouseover=&quot;linkColorOnmouseover(this)&quot; onclick=&quot;function2('bla')&quot;>The link</a>
</body>
 
the syntax is correct for netscape tho
maybe it's just that your 'a' is not recognized as a styleobject : try adding an id or something ? or even tags.a.color=&quot;red&quot; should work
 
Thanks iza.
I can't use id because all of the links
wil have the same id, since the list is built from a database.
 
Why not just define a class?
Code:
<style>
.dblinks {color: #000000;}
.dblinks:hover {color: #FF0000;}
</style>
...
<body>
<a href=&quot;#&quot; class=&quot;dblinks&quot; onclick=&quot;function2('bla')&quot;>The link</a>
</body>
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Doh! I forgot, hover doesn't work in NS4. Sorry, you are going to have to give your links ids. Is it so hard to output a generic id name via the database?
Code:
i.e. (if you were using perl)
for (my $x = 0; $x < @DBOUTPUT; $x++)
{
  print qq~<a href=&quot;$DBOUTPUT[$x]{&quot;link&quot;}&quot; id=&quot;$x&quot; onmouseover=&quot;linkColorOnmouseover($x)&quot; onclick=&quot;function2('$DBOUTPUT[$x]{&quot;click&quot;}')&quot;>$DBOUTPUT[$x]{'text'}</a><br>~;
}
You may have to put your id in a span or div, not sure about that.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Dear Tom:
You are right, hover is not working in NS.
A generic id won't serve my purpose.
I don't need the whole list of links to change colors,
when only one is &quot;hovered&quot;.
I tried it before of course.
I believe it's possible to make differnet id's
if I use a loop (id1, id2, id3).
I'm trying to find an easier solution.
Thanks. I learned a new idea from you anyway.
:)
Avivit
 
even without id you can access every element you've got on the page, as they are part of an array - now, which array, it depends on which dom you are using
for netscrap you should check in the arrays : document.links or document.anchors
so document.links[0] returns the first <a href...> you had (that means if you have a way to know the index of your atgs then it's done !)
you can now loop trough the whole document.links array and check for document.links[the_index].name or .value or .text to compare, in case you don't know the order of the links
 
Thanks iza, that's good to know.
I'll check it out.
 
let me know :cool:
oh yes and when i wrote &quot;atgs&quot; i meant &quot;tags&quot; s-)
 
That's what I meant... each link gets it's own generic id, as in my code I named the id by the loop counter, and then called the function on that same name.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
tanderso. So you and iza basically have the same idea.
I'll check it.
Thanks both.
:)
 
actually tanderso's idea is to name all the links when you create them, in order to easily retrieve them (by name)
mine's is to refer to the links via the ORDER they have in the page
say the first link is <a href=&quot;...&quot;>...</a>
tanderso would have created it this way : <a href=&quot;...&quot; id=2>...</a> and referred it as document.layers.2
i wouldn't have touch it, and referred it as document.links[0]
both give the same result, but you are the only one to know what is feasible for you : naming links while creating them, or knowing their order
hope this is clear, this helps you, and that i didn't twist tanderso's idea too much !



 
iza, no you didn't twist my idea, that is essentially it.

The problem I see with your idea of using the links[] array is that there is no way to determine which link is which unless you do it server-side at the time of creation, like this:
Code:
for (my $x = 0; $x < @DBOUTPUT; $x++)
{
  print qq~<a href=&quot;$DBOUTPUT[$x]{&quot;link&quot;}&quot; onmouseover=&quot;linkColorOnmouseover(document.links[$x])&quot; onclick=&quot;function2('$DBOUTPUT[$x]{&quot;click&quot;}')&quot;>$DBOUTPUT[$x]{'text'}</a><br>~;
}
Otherwise, you couldn't call linkColorOnmouseover() on any particular link without already knowing which link it is, which you cannot determine except by use of the &quot;this&quot; variable, which apparently does not work in NS.

But, if you did the server-side determination of the link order, you might as well use that method to name the link so that you don't have any problems with other links in the page.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
i knew there was some kind of tricky way to &quot;order&quot; the links but couldn't figure out exactly how to .. done thanx to you tom :))))
have a niiiice day :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top