The :empty selector in jQuery is used to select empty elements.
Syntax:
$(":empty")
Parameter: The :empty selector contains a single parameter empty which is mandatory and used to select an empty element which is an element without child elements or text.
Example 1: This example uses :empty selector to select an element position in a table.
<html>
<head>
<title>
jQuery :empty() Selector
title>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
script>
<script>
$(document).ready(function () {
$(":empty").css("background-color", "green");
});
script>
head>
<body>
<center>
<h1 id="geeks1" style="color:green;">
GeeksForGeeks
h1>
<h2 id="geeks2">jQuery :empty() Selectorh2>
<table border="1">
<tr>
<th>Nameth>
<th>Contactth>
<th>Countryth>
tr>
<tr>
<td>Geeks 1td>
<td>td>
<td>Indiatd>
tr>
<tr>
<td>Geeks 2td>
<td>2345td>
<td>td>
tr>
<tr>
<td>Geeks 3td>
<td>3456td>
<td>Indiatd>
tr>
<tr>
<td>Geeks 4td>
<td>4567td>
<td>Indiatd>
tr>
<tr>
<td>Geeks 5td>
<td>5678td>
<td>U.S.td>
tr>
<tr>
<td>td>
<td>6789td>
<td>Austrialiatd>
tr>
<tr>
<td>Geeks 7td>
<td>td>
<td>Indiatd>
tr>
table>
center>
body>
html>
Output:
Example 2: This example use : empty selector to select an empty element.
<html>
<head>
<title>jQuery :empty() Selectortitle>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
script>
<script>
$(document).ready(function () {
$("div:empty(.GFG)").css("background-color", "green");
});
script>
<style>
.GFG {
width: 200px;
height: 40px;
}
style>
head>
<body>
<h1>GeeksforGeeksh1>
<div class="GFG">div>
body>
html>
Output:
