Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

jQuery: Finds all elements that are empty

jQuery Fundamental - II : Exercise-83

Finds all elements that are empty.

Note: Don't have child elements or text.

Sample solution :

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Finds all elements that are empty.</title>
</head>
<body>
<table border="1">
<tr><td>R1C1</td><td></td><td>R1C3</td></tr>
<tr><td>R2C1</td><td>R2C2</td><td></td></tr>
<tr><td></td><td>R3C2</td><td>R3C3</td></tr>
</table>
</body>
</html>

JavaScript Code :

$( "td:empty" )
.text( "Empty!" )
.css( "background", "rgb(255,230,210)" );

See the Pen jquery-fundamental-exercise-83 by w3resource (@w3resource) on CodePen.


Contribute your code and comments through Disqus.

Previous: Removes all child nodes from all paragraphs.
Next: Find all input elements that are enabled.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.