Article From:https://segmentfault.com/q/1010000011699173
Question:
<ul>
    <li class="a">How to select these two elements < /li>< Li class= "a" > < /li>< Li class= "a" > < /li>&lT; Li class= "B" > how to select these two elements < /li>< Li class= "B" > < /li>< Li class= "B" > ≪ /li>< /ul>

How do you select these two elements in CSS with the above code?

Answer 0:
.a {
  color: #f00;
}
.a~.a {
  color: #000;
}
.b {
  color: #f0f;
}
.b~.b {
  color: #000;
}

Answer 1:

li.a:nth-child(1),li.b:nth-child(1){
}

Answer 2:

jqueryObtain

$('.a').eq(0)
$('.b').eq(0)

Answer 3:

document.getElementsByClassName("a")[0];

Answer 4:

var a = document.getElementsByClassName(“a”)[0];
var b = document.getElementsByClassName(“b”)[0];

Answer 5:

The structure you give is not easy to do with the CSS selector. The suggestion is to put a and B in a set of & lt; UL & gt; & lt; / UL & gt; respectively, and then use: first-child pseudo-classes:

.a:first-child{
}
.b:first-child{
}

https://codepen.io/WhiteYin/p…

Answer 6:

.a:first-child{
}
perhaps
.a:nth-child(0){
}

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *