I have a GridView control embeeded inside a div as under
<div id="parentDiv">
Hello how r u
<p>
<asp:GridView ID="grdView" runat="server">
</asp:GridView>
</p>
</div>
What I am trying to achieve is that, to find the Parent element of the grid (which is the “parentDiv”) and set the background color to green.My code(does not work)
$(document).ready(function() {
var parentElement = $('#grdView').parent("div");
parentElement.css("background-color", "#ffaaaa");
});
Relatively to the GridView, you’d better use
closest()method:It will get the corresponding
divbetter thanparent(), since the parent node of the GridView ispelement.UPDATE. In order to set background to the text only, you have to place it in personal
spanordivtag:And then use the following JavaScript code: