w3resource
jquery exercises

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?



New Content: Composer: Dependency manager for PHP, R Programming