1

I have this stuff

<div class="foo">
  <input type="text" name="bar" value="" />
  <a href="javascript:void(0)">foobar 1</a>
</div>
<div class="foo">
  <input type="text" name="bar" value="" />
  <a href="javascript:void(0)">foobar 2</a>
</div>
<div class="foo">
  <input type="text" name="bar" value="" />
  <a href="javascript:void(0)">foobar 3</a>
</div>

<!-- I'm trying with this CSS, but with no luck -->
<style> 
.foo a:first-child {
   display:none;
}
</style>

How can I only display foobar 2 and foobar 3 links?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Ragen Dazs
  • 2,115
  • 3
  • 28
  • 56

3 Answers3

4

The selector should select the first .foo element, not the first a within foo.

.foo:first-child a{
   display:none;
}

See this post for more information on pseudo selectors as well as this working example.

Community
  • 1
  • 1
Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
1

You should move :first-child pseudo-class:

.foo:first-child a {
   display:none;
}

But it requires that div to be the first child of it's parent element.

DEMO

MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
-1

So simple

$('.foo:nth-child(3)')
Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66
suprem
  • 1