This is the suggested answer from the Javascript SO question I have modified it to make it a JSNI:
Element content = DOM.createElement("code");
select(content);
public static native void select(Element el)/*-{
var doc = $wnd.document
, text = $wnd.$(el)
, range, selection
;
if (doc.body.createTextRange) {
range = $wnd.document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if ($wnd.window.getSelection) {
selection = $wnd.window.getSelection();
range = $wnd.document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}-*/;
However when used, it throws:
caused by: com.google.gwt.core.client.JavaScriptException: (TypeError) : Argument 1 of Range.selectNodeContents does not implement interface Node.
What could be wrong with my code?