Search code examples
javascriptjqueryhideparent

jquery get the parent of the parent


I'm trying to hide a layer but can't seem to figure out how to get this working here's what i'm trying

if ($('#dgAvailable_ctl02_lblpricefrom > strong').text() == '£'){
    $('#dgAvailable_ctl02_lblpricefrom').parent().parent().hide()
}

And my code is

<div class="resultsitem" style="background-color: rgb(238, 229, 208);">

<div class="petspeoplecontainer">
<h5><span class="lblpricefrom" id="dgAvailable_ctl02_lblpricefrom"><br>From <strong>£</strong></span></h5></div>

</div>

So i'm trying to hide the layer resultsitem if the text of dgAvailable_ctl02_lblpricefrom = £

Any help would be appreciated

Thanks

Jamie


Solution

  • You can use closest like this:

    if ($('#dgAvailable_ctl02_lblpricefrom > strong').text() == '£'){
        $('#dgAvailable_ctl02_lblpricefrom').closest('.resultsitem').hide()
    }