javascriptgogoquery

goquery get all <p> tags from just one selector


I have the following example

<div class="myClass"> 
    <div> 
        <div> 
            <p>1</p> 
        </div> 
    </div> 
        <p>2</p> 
    <div> 
    </div> 
    <p>3</p> 
</div>

How can I extract the 3 p tags using goquery or CSS selectors (or both) Maybe in this case the selector would be "div.myClass"


Solution

  • You can select all child elements of .myClass with a selector like this:

    .myClass p {
        /* Selects all p elements that descend from .myClass */
    }
    

    A guide about descendant selectors can be found here.