0

I'm trying to figures out why this GwtQuery doesn't work, even how much I click on the label element it doesn't budge:

final Element deleteTD = DOM.createTD();                                            
deleteTD.addClassName("center");
Element span2 = DOM.createSpan();                                   
span2.addClassName("label label-danger");                               
span2.setInnerText("Delete");                               
deleteTD.appendChild(span2);


$(editTD).click(new Function() {                                      
public boolean f(Event e) {                                                   
Window.alert("Edit");                                                     
return false;                                                   
}
});                                         

$(deleteTD).click(new Function() {                                                
public boolean f(Event e) {                                                                                   
return false;                                               
}                                                 
});

row.appendChild(editTD);                                    
row.appendChild(deleteTD);                                  
list.appendChild(row);

Even how much I click, the Window alert doesn't show up, to indicate that the editTD was clicked

quarks
  • 33,478
  • 73
  • 290
  • 513

3 Answers3

0

I guess you need to do event delegation.

$(editTD).bind("click", new Function() {
    @Override
    public boolean f(Event e) {
        Window.alert("editTD");
        return true;
    }
});
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

I was not able to fix the issue with GwtQuery but with:

                                        DOM.sinkEvents(editTD, com.google.gwt.user.client.Event.ONCLICK);
                                        DOM.setEventListener(editTD, new EventListener(){
                                            @Override
                                            public void onBrowserEvent(
                                                    com.google.gwt.user.client.Event event) {
                                                if (event.getTypeInt() != com.google.gwt.user.client.Event.ONCLICK) {
                                                    return;
                                                }
                                                Window.alert("Edit");
                                            }});                                        
quarks
  • 33,478
  • 73
  • 290
  • 513
0

I have never tried with GwtQuery but I think the problem with dom element. because Dom element should add before apply event on it.

Just try to add before row.appendChild(editTD); then add click event. It should work.

Refer example of event. it might same apply with GwtQuery.

Community
  • 1
  • 1
bNd
  • 7,512
  • 7
  • 39
  • 72