1

I'm using gwtquery to manipulate the pages, i found in jQuery i can use:

$('body').removeClass().addClass(myClass);

But seem gwtquery does not provide the same removeClass() method, it only has removeClass(String... classes). It is not quite useful if i want to remove all classes of the Element without knowing the names beforehands.

Anybody who know the counterpart of this method?

Mike
  • 3,515
  • 10
  • 44
  • 67
  • Good find, the GWT query code should behave the same way instead of throwing an exception – logan Sep 30 '12 at 03:03

2 Answers2

1

Short answer:

  • Use setClassName("") on GWT's element class

    $('gwt-Label').widgets().get(0).getElement().setClassName("")

  • Or, set the className attribute directly

    $("gwt-Label").attr("className","")

Long answer:

So, I looked through the two implementations, and they seem to do two different things.

  1. jQuery replaces the className property of the dom element if there are no classes to remove.
  2. GQuery just iterates the classes, and removes them one by one, delegating to GWT's Element dom class. Behind the scenes, this uses the className property.
Community
  • 1
  • 1
logan
  • 3,416
  • 1
  • 33
  • 45
  • Great, the setClassName method is so handy, the GQuery way is more concice i think. – Mike Sep 30 '12 at 03:08
1

I've fixed the issue in gquery. We follow the rule that gquery should behave the same as jquery, so this was a bug in the library. Thanks for realise it.

Update your project to the last gwtquery-1.2.1-SNAPSHOT.jar

Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27
  • HI, Thanks for your wonderful work on gquery. I think there are still a few api(from jquery1.7) not fully supported in gquery, which means, the method implemented but parameter may not fully compatible with jquery(usually lacking). For example, check out http://api.jquery.com/show/, http://api.jquery.com/fadeIn/, http://api.jquery.com/slideDown/ with corresponding gquery api. – Mike Oct 02 '12 at 02:09
  • Yep, gquery lacks of many of method signatures present in jquery, this is so because in java it is necessary a a bit more effort writing overloaded methods, we have tried to implement the most used cases. We normally add those methods if someone asks for that. – Manolo Carrasco Moñino Oct 02 '12 at 07:18
  • In the case of show() it's worth to add the parameters timeout and function. In the other cases it is missing the easing parameter, gquery supports easing in the animate() method so anyone with this problem can use animate as a workaround. Anyway if you miss any method you need in your project open a request or send a patch, we will glad to update the library. – Manolo Carrasco Moñino Oct 02 '12 at 07:28