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="petspeoplecon开发者_如何学Pythontainer">
<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
You can use closest
like this:
if ($('#dgAvailable_ctl02_lblpricefrom > strong').text() == '£'){
$('#dgAvailable_ctl02_lblpricefrom').closest('.resultsitem').hide()
}
The first parent of pricefrom is the h5 and then the container div. What I think you might want is:
$('#dgAvailable_ctl02_lblpricefrom').parents("div.resultsItem").hide();
I'd also note that hard coding your asp.net control IDs like this may cause you problems down the line...
Seems to work here. http://jsfiddle.net/SsVrE/
精彩评论