I have a container with several p
elements and several input
elements. I need to select the last p
element inside this container, and for some reason I'm not able to. I've tried several methods but non seem to work. It must be last-child
and not nth-child
since there might be more elements in the future. Whats the difference between last-of-type
and p:last-child
?
JSfiddle here.
HTML:
<div id="inputContainer">
<p class="contact_title">EMAIL</p>
<p>john@snow</p>
<p class="contact_title">PHONE</p>
<p>123-hodor-hodor</p>
<p class="contact_title">ADDRESS</p>
<p>castle black</p>
<input id="name" placeholder="Name">
<input id="email" type="email" placeholder="Email">
<input id="phone" type="number" placeholder="Phone">
<textarea id="note" placeholder="bla bla"></textarea>
</div>
CSS:
/* not working 1 */
#inputContainer :last-of-type p {
color: red !important;
}
/* not working 2
#inputContainer > p:last-child {
color: red !important;
}
not working 3
#inputContainer p:last-child {
color: red !important;
} */