AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



html-jquery: How to check that a div tag is empty or not in jquery?

I have a div tag and i want to check whether it is empty or not in jquery.

html x 24
jquery x 12
Posted On : 2015-11-18 23:04:29.0
profile Rishi Kumar - anyforum.in Rishi Kumar
523188250048
up-rate
4
down-rate

Answers


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>

Posted On : 2015-11-19 00:15:12
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129560202
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in