title: What exactly acts as a trigger for a custom event in Javascript
body: <p>I've been reading about custom events and looked at some examples. Perhaps I am misunderstanding what custom events are and how they are triggered and would appreciate some help.</p>
  
  <p>Example Problem</p>
  
  <p>To trigger an event when the background colour of a div changes from one colour to another.</p>
  
  <p>Situation A) The colour changes as result of user activity detectable from within the script, eg by onclick, onmouseover, onkeypress then I would set up a listener for these events and respond accordingly. This I understand how to do.</p>
  
  <p>Situation B) The colour changes as the result of user activity not detectable from within the script, eg a new theme applied to the page, then am I correct in thinking the following are necessary?</p>
  
  <ol>
  <li>I would need to create a custom event for colour change.</li>
  <li>Add a listener for the event to the appropriate DIV</li>
  <li>The listener would need to poll the DIV at intervals to check for colour changes</li>
  </ol>
  
  <p>Really its step 3 I am not clear about. If you are not polling the DIV how does the event colour change trigger an event? In other words how does the script know that a colour change has taken place?</p>