I need to select all children of an element except the first one. I am working with drupal and colorbox module, and I can't add unique classes or an ID to the first element alone.
<span>
<span>
<a> </a> <a> <img> </a>
<a> <img> </a>
<a> <img> </a>
</span>
</span>
I have that structure and
can have more <a> <img> </a>
but you get the idea.
In short. I need to select all the image tags inside the a tags <a> <img> </a>
so I can apply a CSS rule to them, without affecting the first <a>
tag. Maybe there's a Jquery solution to this? Thank you
Use :not(:first-child)
to exclude the first link
.myClass img {
content: url('http://kenwheeler.github.io/slick/img/lazyfonz2.png');
}
.myClass a:not(:first-child) img {
content: url('http://kenwheeler.github.io/slick/img/lazyfonz3.png');
}
<span>
<span class="myClass">
<a> <img> </a>
<a> <img> </a>
<a> <img> </a>
</span>
</span>
It's basically the same thing in jquery.
$('a:not(:first-child)').css('background','red');
a {
height: 1em;
width: 1em;
background: black;
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span>
<span>
<a> <img> </a>
<a> <img> </a>
<a> <img> </a>
</span>
</span>