Jump to content

:nth-child()


VanityCrush
Go to solution Solved by maxxd,

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
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.