You can use is(´:empty´) to check whether a div tag is empty or not. But is(´:empty´) works only when we don´t have even white space in div tag. In that case we can use html() which return the html code written in that div tag or to get the displayed text use text() and then call trim() to remove the white spaces and check it with blank string. See below example:
FindBlankDiv.html:
-------------------------------------------------
<html>
<head><title>Finding Empty HTML Tag- anyforum.in</title>
</head>
<body>
<div id="third">
</div>
<div id="fourth"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
if($(´#third´).text().trim()==""){
alert("Third is empty checked by text() method");
}
if($(´#third´).html().trim()==""){
alert("Third is empty checked by html() method");
}
if($(´#fourth´).is(´:empty´)){
alert("fourth is empty checked by empty property");
}
</script>
</body>
</html>
|