setting the style of a child object

M

mark | r

i use document.getelementbyid('id').style.colour= a lot anyone know how to
set the style of the link in the following code

<li id="tab1"><a href="#">moo</a></li>

because setting the colour of tab1 doesnt work.

Mark
 
E

Evertjan.

mark | r wrote on 24 jan 2005 in comp.lang.javascript:
i use document.getelementbyid('id').style.colour= a

Mind the case sensitivity
lot anyone know
how to set the style of the link in the following code

<li id="tab1"><a href="#">moo</a></li>

because setting the colour of tab1 doesnt work.

<style>
.coloured {color:red;}
.coloured a {color:green;}
</style>

<li><div id="d">Hello <a href="#">World</a></div>

<script>
document.getElementById('d').className= "coloured"
</script>
 
R

RobG

mark said:
i use document.getelementbyid('id').style.colour= a lot anyone know how to
set the style of the link in the following code

<li id="tab1"><a href="#">moo</a></li>

because setting the colour of tab1 doesnt work.

Because setting the colour of tabl *does* work, but "moo" is inside an
'a' tag that will not change when you modify the 'li' tag.

Borrowing from Evertjan:

<html><head><title>play</title></head>
<body>

<li><div id="d" onclick="makeMeRed();">Hello <a
href="#">World</a></div>

<script type="text/javascript">
function makeMeRed() {
document.getElementById('d').style.color = 'red';
}
</script>
 
M

mark | r

Evertjan. said:
mark | r wrote on 24 jan 2005 in comp.lang.javascript:


Mind the case sensitivity


<style>
.coloured {color:red;}
.coloured a {color:green;}
</style>

<li><div id="d">Hello <a href="#">World</a></div>

<script>
document.getElementById('d').className= "coloured"
</script>

no, wait, i get it, it dynamically sets a class for the div containing an
ID - how do you set this to none?

mark
 
M

Michael Winter

i use document.getelementbyid('id').style.colour= a lot anyone
know how to set the style of the link in the following code

<li id="tab1"><a href="#">moo</a></li>

because setting the colour of tab1 doesnt work.

In theory it should, however user agents tend to treat link colours
specially.

If there's no whitespace between the start tags for the list item and
anchor elements, you could use

document.getElementById('tab1').firstChild.style.color = ...;

adding appropriate feature detection, of course.

Mike
 
E

Evertjan.

mark | r wrote on 24 jan 2005 in comp.lang.javascript:
no, wait, i get it, it dynamically sets a class for the div containing an
ID - how do you set this to none?

Elementary, my dear Watson:

document.getElementById('d').className= ""

[I had to test it, perhaps amazingly and it works]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top