title: GWT: Add an event handler on all div elements
body: <p>How to add an event handler on all div elements with GWT?
  I tried the following code but the window alerts are not fired up (But "etvoila" class is set up):</p>
  
  <pre class="lang-java prettyprint-override"><code>  private NodeList&lt;Element&gt; pageDIVElements;
    public void initDiv() {
      MyDIVEventHandler handler = new MyDIVEventHandler();
      pageDIVElements = Document.get().getElementsByTagName("div");
      for (int i = 0; i &lt; pageDIVElements.getLength(); i++) {
        Element elem = pageDIVElements.getItem(i);
        elem.addClassName("etvoila");
        com.google.gwt.user.client.Element castedElem = (com.google.gwt.user.client.Element) elem;
        DOM.setEventListener(castedElem, handler);
      }
  
  class MyDIVEventHandler implements EventListener {
    private Element divElement;
    @Override
    public void onBrowserEvent(Event event) {
  
      Window.alert("Yeepee");
      if (event.equals(Event.ONMOUSEOVER)) {
        Window.alert("ONMOUSEOVER");
        divElement = Element.as(((NativeEvent) event).getEventTarget());
        divElement.setPropertyString("background-color", "#C6D4E6");
      } else if (event.equals(Event.ONMOUSEOUT)) {
        divElement = Element.as(((NativeEvent) event).getEventTarget());
        divElement.setAttribute("background-color", "");
      }else if (event.equals(Event.ONCLICK)) {
        divElement = Element.as(((NativeEvent) event).getEventTarget());
        divElement.setAttribute("background-color", "");
        Window.alert("ONCLICK");
      }
    }
  }
  </code></pre>
  
  <p>What is wrong in this method?</p>