How to Use JQuery in GWT

After adding the JQuery script to your project HTML file’s head­er sec­tion

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>

You will be able to use JQuery in native (JSNI) meth­ods by prepend­ing $wnd., e.g.:

private native void someMethod() /*-{
	$wnd.$(function() {
		$wnd.$('#somediv').doSomething();
	});
}-*/;

With­out $wnd. you will end up with fol­low­ing error: com.google.gwt.core.client.JavaScriptException: (ReferenceError): $ is not defined

3 Replies to “How to Use JQuery in GWT

Leave a Reply

Your email address will not be published. Required fields are marked *