jquery empty - remove html tag if no contents
How to remove html tag if it does not contain text or content.
if using <p></p> code is working,
but
if using
<p>
</p>
The code is not successful
jquery
$(document).ready(function(){
$("button").click(function(){
$('#demo p:empty').remove();
});
});
html
<p>
</p>
==================================
$(document).ready(function(){
$("button").click(function(){
$('#demo p:empty').remove();
});
});
p {
background:red;
color:white;
height:20px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<button>Run</button>
<div id='demo'>
<p>
</p>
<p>
Lorem Ipsum .....
</p>
</div>
</body>
</html>
Thank you in advance