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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/jquery-exercises/2/jquery-fundamental-exercise-83.php