473,756 Members | 8,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DHTML basics - how to change css property?

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="anchor name('#tech02') </a></span></p>

Which calls this function:

function anchorname(n) {
var a=(window.locat ion.hash);
if n=a {
changeproperty span(currentlin k).color=#CC000 0;}
}

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...
Jul 23 '05 #1
2 4117
> 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?
Jul 23 '05 #2
DU
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="anchor name('#tech02') </a></span></p>

Which calls this function:

function anchorname(n) {
var a=(window.locat ion.hash);
if n=a {
changeproperty span(currentlin k).color=#CC000 0;}
}
Much more compact, versatile is:

<p><a href="techpage. php#tech02" onclick="Change Color(this);">S ome
descriptive text</a></p>

function ChangeColor(obj ElementTarget)
{
if(objElementTa rget && objElementTarge t.style)
{
objElementTarge t.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
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1932
by: Chris Leonard | last post by:
Hi. I've copied some code from a book which will enable me to make a layer around a page, my aim is to do something a little more complex but this I thought would get me started. Anyway, I've run into a problem before I even start! The script works OK, it runs the image in from the left hand side quite nicely, great. Problem I have it always scrolls up to the top of the page, when the link I click maybe 2 or 3 screens below (does that...
2
1797
by: Kurien Baker Fenn | last post by:
I would like to show the progress of an application using the progress bar in visual basics using the timer.Please help me. Thanks in advance.
2
1644
by: Frances Del Rio | last post by:
please, can you go to http://www.francesdelrio.com/dhtml/ when you click the name of the character the font color for all the lines of that character should change.. this is a simple DHTML memo... but I find that none of the JS or DHTML code is working at all on page... if I download page and view it locally the JS & DHTML code work fine, I don't understand this.. I'm very anxious b/c I just submitted this page as a demo for a...
3
1402
by: Chris Ryan | last post by:
Is there a way to change the displayed text on a web page using some combination of Javascript and DHTML? NOT in a text box. As far as I know (with my limited knowledge) the only way you can do this is with a textbox or images, which is not what I'd like to do. There's gotta be a way to do this, right?
12
2772
by: ATS | last post by:
I need to hide/reveal parts of a web page using javascript. I think I can do with using the <span> tag, but I've been away from it for a while and don't remember. Any pointers, examples?
2
1999
by: mr_burns | last post by:
hi there, i would like a book that will explain concepts of javascript and dhtml instead of, for example, ten tutorials on how to do specific things in js or dhtml. ideally a book thats can explain from the basics of javascript, to more complex things such as dhtml and dom onto things like creating javascript objects (if that is possible, but u get the idea). rather than this is how you make a drop down menu tutorial; this is how you
9
1782
by: bissatch | last post by:
Hi, Is it possible to change the class style of an HTML element using DHTML? For example... <td class="my_class">Text</td> I have used DHTML to change style elements such as backgroundColor so I assume that it can be used to change the class too.
6
5266
by: Jon Davis | last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using: <object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object> My question is how do I access the document DOM of this object in Javascript? For example, "alert(extendedhtml.innerHTML);" doesn't work and produces an unknown error. I'd like to both read and write to the document's body element's innerHTML...
3
2530
by: aspmonger | last post by:
Hello, I really believe that IE 6 has a new (intentional?) bug that severely limits the capability of dhtml and cross domain scripting. Yesterday, I read an interesting article about the subject and it only supported my claim. The article explained why Microsoft will not be letting the IE DHTML Implementation get any more powerful than it already is. Microsoft has realized that an experienced DHTML developer can create a web application that...
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9873
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.