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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS and links 1

Status
Not open for further replies.

robert89

Technical User
Nov 19, 2003
125
CA
Is it possible to assign a href to a class. For example, a long document with a name that is repeated throughout. The name is assigned a class and that class has a link within it so if the name is clicked the user goes where ever?

Just wondering!
Bob
 
Code:
<script>
myLink = '[URL unfurl="true"]http://localhost';[/URL]
links = document.getElementsByTagName('A');

for (c=0;c!=links.length;c++){
if (links[c].href==myLink) links[c].className = 'myLink';
}
</script>

<style>
.myLink {color:green;background-color:gold;}
</style>

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Oops! I misread the question.

The answer is yes, you parse the document.body.innerHTML for the keyword and replace it with <a href="">keyword</a>

I wrote a script that did something very similar for a guy in this forum a while ago. You might be able to find it in search. If not, I can write it again :)

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 

Bob,

While there is some CSS to allow you to add content before and after elements, it's has little support, and I don't believe it lets you add elements, although I've not tried this.

That aside, your best bet would be to ask in the JavaScript forum (forum216) for a solution similar to the one Glen is describing - or use server-side technology to deliver the page and parse the content that way.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Stormbind,
Thanks very much. I can give this a go. Will let you know if it works for what I have in mind.

Thanks again,

Dan,
Thanks for the pointer to possible solutions.

Since you guys actually answered the question. I have another. I am looking for a DHTML book and/or javascript book that translates the language to plain english with lots of examples. Any suggestions?
Bob
 
As a rule of thumb, I trust O'Reilly to publish valuable books, but I have not read any of their JS books.

You can find a lot on DHTML and JScript at
See: Web Development > Windows Scripting Technologies > JScript > Reference

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Hi Glen,
Thanks again. I'll take a look.
Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top