views:

485

answers:

2

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? Thanks.

+2  A: 

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...)

mjv
Good point. But the situation for me now is that I have to use JavaScript code to do something like this instead of solving it by GWT code.
Ben
I would also discourage using JS where problem can be solved using GWT. Also if there are specific things you need from jQuery, perhaps you can use GQuery, which is port for GWT? 2c.
sbidwai
In my situation, I sorta have to use JavaScript to process a page generated by GWT. If I have the control of that GWT codes, I understand that I should solve the problem in GWT. BTW, I think GQuery is not a port for GWT. It is just a jQuery-like API for GWT.
Ben
A: 

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).

Igor Klimer