Css: last-child

<div>
    

<p style="display:none">

</div>
css
p:last-child {
    color: red;
}

how can I make the last p element shown turn red

Css
Jun.18,2021

you can use jQuery to solve the problem that
directly selects the last p element to see if it is hidden. If it is hidden, then its previous element sets the style, otherwise it sets the style for this last element

<body>
    <div>
        

1

2

<p style="display:none">3

</div> </body> <script src="../echarts/jquery-3.1.0.min.js"></script> <script> if($("p:last").is(":hidden")){ $("p:last").prev().css("color","red") }else { $("p:last").css("color","red") } </script>

tried

p:not([style="display:block"]):last-child

but it has no effect

Menu