package com.example.gwt.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.RootPanel; public class Example implements EntryPoint { @Override public void onModuleLoad() { Button button = new Button("Click me"); RootPanel.get().add(button); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Element el = Document.get().getElementById("my-div"); el.getStyle().setBackgroundColor("#ff0000"); } }); } } 

Here is the HTML code:

 <html> <head> <title>Hello my Dear friend</title> <link rel="stylesheet" href="style.css"> <div id="my-div" ></div> </head> <body id="bodyId"> <script type="text/javascript" language="javascript" src="com.example.gwt.Examp/com.example.gwt.Examp.nocache.js"></script> <h1>Example Application</h1> </body> </html> 
  • try adding a minimal reproducible example to the question - Mikhail Vaysman
  • one
    why do you have a <div> in <head> ? - Nofate
  • Should it be in Body? - SuperBo
  • Yes, it should be. Before you take on the GWT, you should understand the basics of HTML / CSS, because ultimately everything is built upon them. - Nofate

0