deko wrote:
> I'm trying to change the font style of a link when that link is clicked.
> But the link (sometimes) includes a named anchor. So I need to test for a
> given named anchor and apply style changes if the test is true - since there
> will be several different named anchors in the page. I don't think this is
> very advanced, but I'm new to JavaScript .
>
> I code the link like this:
>
> <p><span id="currentlink"><a href="techpage.php#tech02"
> onClick="anchorname('#tech02')</a></span></p>
>
> Which calls this function:
>
> function anchorname(n) {
> var a=(window.location.hash);
> if n=a {
> changeproperty span(currentlink).color=#CC0000;}
> }
Much more compact, versatile is:
<p><a href="techpage.php#tech02" onclick="ChangeColor(this);">Some
descriptive text</a></p>
function ChangeColor(objElementTarget)
{
if(objElementTarget && objElementTarget.style)
{
objElementTarget.style.color = "#C00";
};
}
With this code, the "Some descriptive text" should change color to
#CC0000. There could be other ways to achieve this, depending on your
webapge requirements, analysis, etc. E.g.: an entirely CSS solution
a:active {color: #C00;}
>
> That function is pretty much pseudo code. What it needs to do is change the
> properties of the css id - which I assume would be declared in a span around
> the link. Is the link code correct? The function? Both wrong?
>
> Any help is appreciated...
>
>
Using Web Standards in Your Web Pages
Accessing Elements with the DOM
http://www.mozilla.org/docs/web-deve...tml#dom_access
Making your web page compatible with Mozilla
http://www.reloco.com.ar/mozilla/compat.html
Updating DHTML Web Pages for next generation browsers
http://devedge.netscape.com/viewsour...tml-web-pages/
My javascript section:
http://www10.brinkster.com/doctorunc...scriptCSS.html
DU