Jump to content

:nth-child()


VanityCrush

Recommended Posts

Hello,

 

I have an unordered list with 5 classes (don't ask)..

<ul class="error_list reg_errors chpw_errors actv_errors profile_errors">

I have used .error_list:nth-child(1) to target reg_errors and .error_list:nth-child(2) to target chw_errors class.

 

How can I target the 5th class of this element without using :last-child? [i will be adding more classes to it]

 

I've tried

 :nth-child(5n+1)

and it works, however it is also targeting the reg_errors class. I know this is a mess, but I can't find a better solution as I need to dynamically generate each class depending on the user's action.

Link to comment
https://forums.phpfreaks.com/topic/297629-nth-child/
Share on other sites

I'm not quite sure what you're asking here. Are you trying to target DOM elements with a class of 'reg_errors' and/or 'chpw_errors', or are you trying to target the selectors themselves? If I'm reading your post correctly, that's not how nth-child() works - take a look here and here.

 

Explain a bit more about what you're trying to do, what you expect to happen, and what's happening right now, and we'll be better able to help.

Link to comment
https://forums.phpfreaks.com/topic/297629-nth-child/#findComment-1518141
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.