Ben
Ben

Reputation: 171

GWT and jQuery: how to use jQuery to remove Events generated by GWT code

How can I use jQuery to remove a click event on an Anchor generated by GWT? For example, I have some GWT code like this:

Anchor a = new Anchor("name")
a.addClickHandler(new ClickHandler(){
    public void onClick(ClickEvent event) {
        //do something
    }
});

So it generates HTML code like this:

<a tabindex="0" class="gwt-Anchor" href="javascript:">name</a>

In non-IE, I can use this:

$('a.gwt-Anchor').attr("onclick",function() {return false;});

to disable the click event, but this does not work for IE. And I am trying to use unbind() method, it does not work either. Is there a way to do this?

Upvotes: 1

Views: 1185

Answers (2)

Igor Klimer
Igor Klimer

Reputation: 15321

Have you tried the methods of the Event object mentioned here: http://docs.jquery.com/Events/jQuery.Event? preventDefault() looks promising.

GWT's ClickEvent also has a preventDefault() function, if you're interested :) (I agree with mjv in that this should be done in GWT - I only use external JS libraries for complex stuff, like UI effects, AJAX push, etc).

Upvotes: 0

mjv
mjv

Reputation: 75125

Is there a way you could build this logic within the java source, instead ?

I think that one of GWT's purposes is to free developers from dealing with browser-side implementation specifics. But by altering GWT-produced client-side code, one creates a rather strong coupling with undocumented GWT behaviors (for example what happens if say, the next release of GWT uses the class 'GWT-SimpleAnchor' for most its a tags, or something like that, or say it alters the way it produces IE 7.0 but not IE 8.0...)

Upvotes: 2

Related Questions