0

I want to know why JQuery is not applying the border-bottom css property when I apply the addCLass method. It applies the colour but not the border. Why is that? JSFiddle: http://jsfiddle.net/egh7a/

Thanks.

html

<section class="news"> <article>one</article> <article>two</article> <article>three</article> <article>four</article> </section> 

jQuery

$(".news article:last").addClass("two"); 

css

.news { border-top: 1px solid #777; } .news article { padding-top: 10px; padding-bottom; 10px; border-bottom: 1px dashed #999; } .two { color: red; border-bottom: black solid 2px; } 
1
  • specificity my friend Commented Jul 1, 2013 at 9:30

2 Answers 2

5

The article item takes its style from the more specific css rule.

In this case .news article is more specific than .two.

Try changing your .two class to .news .two instead.

Sign up to request clarification or add additional context in comments.

Comments

2

Because the new border style isn't overriding the last one. You can use !important to override it.

.two { color: red; border-bottom: black solid 2px !important; } 

JSFiddle

4 Comments

Don't use !important if you can avoid it. It should only be used as a last resort.
If you know what you are doing, using !important can save you a lot of time. This is just an example how the OP can fix the issue without changing its class selectors.
you can add parent class before that to show how to fix the issue don't tell anybody anything which is not in standards. :)
Yes, if you know what you are doing. But what about when you suddenly need to override the !important rule? The only way to override !important is to have another rule with !important with a specificity that is higher than the first !important rule, which brings you back to square one. All recommendations point in the same direction - !important is last resort only.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.