I have javascript code that checks if a div has non-contextual text content.
This works, but it cannot distinguish between text content or style tag declarations in a div, and the test fails when there is no text content other than a style tag with css data.
The question is how to check for empty text content while ignoring a style tag?
HTML:
<div id='test1'>
<div> </div>
</div>
<div id='test2'>
<div> </div>
<style>
.style1{
border:1px;
}
</style>
</div>
JavaScript:
if($('#test1').text().trim().length==0){
alert('test1 has no content!');
}
if($('#test2').text().trim().length==0){
alert('test2 has no content!');
}
Test URL:
http://jsfiddle.net/sLDWB/
source
share