0
<a id='123' href='www.stackoverflow.com'>
Hello <span style='color:#c0c0c0;text-decoration: underline;'>World</span>
</a> ​

I currently change the link color by doing this

var chosenclass = document.getElementById('123');
chosenclass.style.color = '#000000';

But now I'd like to change the span by only having a reference to the chosenclass object. How can I do that ?

1
  • 123 is an invalid id :) If I am not mistaken they should start with a letter. Commented Jan 8, 2013 at 20:52

1 Answer 1

3
chosenclass.children[0].style.color = '#000';
Sign up to request clarification or add additional context in comments.

2 Comments

except children[0] is going to be a text node and not the span, I believe.
No, children refers only to element children. childNodes includes text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.