I have a list with a specific li style. I want to replace the style of an individual element, but it has no visual effect. Example:
.myList li {
background-color: yellow;
}
.foo {
background-color: green;
}
<ul class='myList'>
<li>Hello</li>
</ul>
When I add an item to the list, it correctly applies the .myList li style. I am trying to remove all styles and apply foo style to one element (using jquery):
$(item).removeClass();
$(item).addClass("foo");
the element does not change color to green, but it reports that the class is set to "foo":
alert($(item).attr('class'));
so I think I don’t understand the CSS rules here, it looks like the definition of the li class just overrides everything I do, however I want the opposite to be true, I want to override the li style definition with foo. How do we do this?
thank
source
share