Reputation: 8020
I'm trying to use javascript to change the color of a specific li of a ul, but my code is highlighting all subsequent li of the list. Here is the code:
<ul list style type = "none">
<li id = "l0">this is line one</li>
<li id = "l1">this is line two</li>
<li id = "l2">this is line three</li>
</ul>
function highlight(name,color) {
var a = document.getElementById(name);
a.style.color = color;
}
When I call this with something like
highlight("l0","orangered");
it changes the colors of "l0" through "l2", instead of just "l0". I would very much prefer a solution using only javascript, rather than a 3rd party library. Thanks!
Upvotes: 2
Views: 12745
Reputation: 550
That's a bizarre bug. I've just tried doing what you did, and it worked fine for me: http://jsfiddle.net/4aGag/
Upvotes: 0
Reputation: 6617
I made a fiddle using your js function: http://jsfiddle.net/Ahb8F/
It works fine, did you expect/want something else?
Upvotes: 3