You can use $("p.ABC") to find all <p> with class ABC then .closest(".b") to find the parent div with class b then .css() to change css properties.
I recommend using .addClass() / .removeClass() rather than change css directly, but this helps you find the parent.
This also allows you to have multiple div class='b' in your html and it will only apply to the one with ABC
$("p.ABC").closest(".b").css("background-color", "pink");
.b+.b {
border-top: 1px solid black;
margin-top: 5px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="b">
<h1>Hello</h1>
<div class="a">
<p class="ABC">A........Z</p> //this could be present in some pages
</div>
</div>
<div class="b">
<h1>Hello</h1>
<div class="a">
<p class="DEF">ABC not present</p>
</div>
</div>
You can also turn it around using :has
$(".b:has(.ABC)").css("background-color", "pink")
which states: select all .b that has at least one child that has class .ABC, which is nearer to your concept of: add css to div with class "b" if <p> contains class="ABC"
So it depends on which way you want to work it.
$(".b:has(.ABC)").css("background-color", "pink")
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="b">
<h1>Hello</h1>
<div class="a">
<p class="ABC">A........Z</p> //this could be present in some pages
</div>
</div>
<div class="b">
<h1>Hello</h1>
<div class="a">
<p class="DEF">ABC not present</p>
</div>
</div>