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
  • 665,005
  • 155
  • 1,345
  • 1,328
Ragen Dazs
  • 2,045
  • 3
  • 25
  • 54

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
  • 90,944
  • 18
  • 150
  • 184
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
  • 121,297
  • 15
  • 183
  • 252
-1

So simple

$('.foo:nth-child(3)')
Alex Karshin
  • 12,300
  • 14
  • 50
  • 60
suprem
  • 1