I am trying to add this code to the chrome extension to alert me when a chat panel is available. Its in a div with the class name shoutbox so far it doesn't work.
function Detection(){ if(document.getElementsByClassName("shoutbox")!=null){ alert('Chat is available.') } } Detection();
Updated code: the page loads and the warning dialog does not appear.
function Detection(){ if(document.getElementsByClassName("shoutbox").length > 0){ alert('Chat is available.') } } window.onload = Detection;
== nullwill not detect an empty array (no results). You can write
== null
if(document.getElementsByClassName("shoutbox").length > 0){ alert('Chat is available.') }
document.getElementsByClassName("shoutbox")returns an array of elements and returns an empty array if it does not find anything. To find out if elements exist, check the length of the array.
document.getElementsByClassName("shoutbox")
if(document.getElementsByClassName("shoutbox").length > 0){
chatbox ( - ), DOMSubtreeModified, , - DOM
DOMSubtreeModified
document.addEventListener('DOMSubtreeModified', function(e) { if(document.getElementsByClassName("shoutbox").length > 0){ alert('Chat is available.') } });