I want to check a div is empty or not.
HTML
<div id="check"> </div>
Script
$(document).ready(function() {
var $tr = $('#check');
if ($tr.text())
{
alert("success");
}
else
{
alert("fail");
}
});
The problem is empty space is also considering as text. This should be succes only when content is present inside the div.
Can you please help me to perform this?
Thanks!
Change:
to:
This will remove any white space before and after your string and then check the resultant length.
jsFiddle example
Ref: http://api.jquery.com/jQuery.trim/