JS do something if container is not empty

Check if a specified ID has content. If yes, do something. In this example I specify the ID with “#checkid”. Do stuff if there is content – or if not.

if
(document.getElementById("checkid").innerText.length > 0){
console.log("yes"); // what should be done if there is content
} 
else{
console.log("no"); // what should be done if there is no content
};

WHERE TO PLACE THIS CODE?

Run it within your tag manager or put it on your desired page. Either within a script file, or within the  <style> ... </style> tags.

Pleasure?

Please share your thumbsup, suggestions, edits, and questions within my comment section down there. 

I love posting snippets for you, but with a bit of feedback, it gets even more fun. 😀

Sharing is caring:

Share on xing
Share on linkedin
Share on whatsapp
Share on facebook
Share on twitter
Share on email

Leave a Reply

Your email address will not be published.