information
I tried two methods with problems:
1. Use the ID directly. But this will conflict with other pages of the website (similar structure, with duplicate IDs)
2. Use class1 :nth-child(1) :nth-child(3) :nth-child(1) :nth-child (1). But when the selector uses an nth-child, it not only selects the nth child element, but also selects the child elements of the nth child element, causing a conflict.
Is there any method as follows:
1. Select by ID number among the descendant elements of class1?
2. How to use nth-child correctly to select only the nth element without involving other descendants?
If you have other methods, please let us know, thank you!
Reply to discussion (solution)
$('.class1 div div div #p0c1')
Second question:
The structure result I copied from your code can be used with this one. Maybe there is something wrong with the structure you gave me, so it is different from yours (:nth-child(1) :nth-child(3) : nth-child(1) :nth-child(1)) There is a slight discrepancy, but it is not a big problem
$('.class1 div:nth-child(1) div:nth-child(1) div:nth -child(2) #p0c1')
Tried this method
nth-child(1)
The result can be summarized as:
This nth-child(n) It works for all child elements that have a parent element. Of course, if you used .class1 div:nth-child(1) div:nth-child(1) div:nth-child(2) before, you want to add another filter later: nth-child(1) means that all levels of child elements in that string of results (actually including all descendants) will become the return result as long as they match
For example:
div: nth-child(2)
If you use this directly as a selector, then all elements in the entire HTML that meet the following points will become the result
1. This has a parent element
2. This child element is ranked Second, there is an older brother
3. This element is div
Yes, I understand the explanation of the second nth-child , it is indeed a headache. Fortunately, the first one seems to work. I will be able to confirm whether it is useful after I have free time in the evening to run the program. Thank you in advance.
Host, please sort out the structure first. To distinguish different things, you can use id, which is unique.
Owner, please sort out the structure first. To distinguish different things, you can use id, which is unique.
Other web pages also have this ID, so using only the ID will cause conflicts.
$('.class1 div div div #p0c1')
Basically the problem is solved. I still need to test it when I go to the company on Monday, but it should work. Thank you!