I was just wondering how can I check if a div has no children because I need to place a placeholder text if the element does not load into the specified div.
Here is my code:
var test = ($('#'+chartId)).children().length;
console.log(test);
if(test==""){
alert('empty');
}
else{
alert('present');
}
Will this work if I'm trying to detect if a flash component is being loaded to a div?
.length is 0 and not empty when there are no childrens. Also you can shorten your code a bit, like so:
if(!($('#'+chartId)).children().length){
alert('empty');
}
else{
alert('present');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With