Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > DHTML basics - how to change css property?

Reply
Thread Tools

DHTML basics - how to change css property?

 
 
deko
Guest
Posts: n/a
 
      08-03-2004
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;}
}

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...


 
Reply With Quote
 
 
 
 
deko
Guest
Posts: n/a
 
      08-04-2004
> 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 .


Actually, the link I want to change is not clicked - so I need to use onLoad
in the body tag (I think)...

Does this mean the function would have to loop through each link in the page
and change the color based on the location.hash? Would each link need a
spearate ID?

<p><a href="tech.php#tech01">Tech01</a></p>
<p><a href="tech.php#tech02">Tech02</a></p>
<p><a href="tech.php#tech03">Tech03</a></p>

How to change the color of only #tech02 when the page loads, and the current
named anchor is #tech02?


 
Reply With Quote
 
 
 
 
DU
Guest
Posts: n/a
 
      08-04-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Changing an elements CSS class style with DHTML bissatch@yahoo.co.uk Javascript 8 05-24-2005 10:48 PM
Do any DHTML books cover contemporary DHTML? Steve Javascript 1 04-09-2005 04:16 PM
good books/websites on javascript/dhtml/dom/css mr_burns Javascript 2 12-22-2004 01:18 PM
help with css and dhtml menu and form problem mark | r HTML 4 09-02-2004 05:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57