- This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
Viewing 8 posts - 1 through 8 (of 8 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I’ve got some HTML that looks like this:
<div class="chicken"></div>
<div class="chicken"></div>
<div class="egg"></div>
<div class="egg"></div>
<div class="chicken"></div>
<div class="egg"></div>
How do I target the third chicken classed div specifically?
I put my html inside the three back-ticks but it seems to have disappeared. Some advice on posting?
Test…
Nope, no advice to be given I think. Used to work that way. It seems to be filtering out all HTML.
I don’t think there is a “nth instance of a class” selector in CSS by the way.
neither nor..
try something like this
$(".chicken").filter(function(index, element){
return index % 3 == 2;
}).addClass("third");
Hey chris_2080, thanks for this however I am not a coder as such which is why I was looking for a CSS solution. According to Shikkediel there may not be one… Your (jQuery?) solution may work but I will need to get a little help in working out how to use it.
ok, jQuery is not needed, put this script into your html at the end of body between script tag
var thirdChicken = document.getElementsByClassName("chicken")[2];
/* do something with thirdChicken */
what is your goal?
I don’t think there is a “nth instance of a class” selector in CSS by the way.
This is correct.