Home >>jQuery Tutorial >jQuery Parent Selector

jQuery Parent Selector

jQuery Parent Selector

jQuery Parent selector in jQuery used to selects all elements that are the parent of another element, including text nodes.

Syntax:
$(":parent")
Here is an Example of jQuery :parent Selector

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("td:parent").css("background-color", "#97d7fc");
});
</script>
</head>
<body>
<h1>Welcome to Phptpoint</h1>
<table border="1">
<tr>
<th>Company</th>
<th></th>
<th>Country</th>
</tr>
<tr>
<td>AB Ltd.</td>
<td></td>
<td>Italy</td>
</tr>
<tr>
<td>CD Ltd.</td>
<td></td>
<td>France</td>
</tr>
<tr>
<td>EF Ltd.</td>
<td>Fourth</td>
<td></td>
</tr>
<tr>
<td>GH Ltd.</td>
<td></td>
<td>Austria</td>
</tr>
<tr>
<td>IJ Ltd.</td>
<td>Sixth</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td>Canada</td>
</tr>
<tr>
<td>XY Ltd.</td>
<td></td>
<td>Germany</td>
</tr>
<tr>
<td>MN Ltd.</td>
<td>Ninth</td>
<td>India</td>
</tr>
</table>
</body>
</html>

Output:

Welcome to Phptpoint

Company Country
AB Ltd. Italy
CD Ltd. France
EF Ltd. Fourth
GH Ltd. Austria
IJ Ltd. Sixth
Canada
XY Ltd. Germany
MN Ltd. Ninth India

No Sidebar ads