I can not understand how to set the selector to select the element I need

For example, there is an html code:

<div class="inner"> <div class="a-row" style="position: relative"> <div class="a-row a-size-small s9Brand">Home</div> <span class="a-color-price a-size-base">$8.99</span> <div class="a-icon a-icon-img a-icon-small" style="margin-left: 4px"><span class="a-icon-alt">price</span></div> </div></div> <div class="inner"> <div class="a-row" style="position: relative"> <div class="a-row a-size-small s9Brand">Home</div> <span class="a-color-price a-size-base">$8.99</span> </div></div> 

I want to remove the inner element and all that is inside it, all I need to do is remove the element in which there is an element with the class a-icon

    1 answer 1

    It is necessary to use the has selector

     $('.inner:has(.a-icon)').remove(); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="inner"> <div class="a-row" style="position: relative"> <div class="a-row a-size-small s9Brand">Home to delete</div> <span class="a-color-price a-size-base">$8.99</span> <div class="a-icon a-icon-img a-icon-small" style="margin-left: 4px"><span class="a-icon-alt">price</span> </div> </div> </div> <div class="inner"> <div class="a-row" style="position: relative"> <div class="a-row a-size-small s9Brand">Home should stay</div> <span class="a-color-price a-size-base">$8.99</span> </div> </div> 

    • thanks a lot earned, tell me more please, the content is updated using ajax (dynamically) (I don’t know how to explain correctly), and the script $('.inner:has(.a-icon)').remove(); It works when you first load the page, but if you go to another page with content, the elements are not deleted, is it possible to somehow wrap the script in a dynamic update too ?? - Pasha Palienko
    • @ PashaPalienko, add a call to the success request handler - Grundy
    • not strong in jquery, can i have an example - Pasha Palienko
    • @ PashaPalienko, nope, I don’t know how or what you are called to - Grundy