Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the difference between $doc.getElementById("id") and document.getElementById("id") in JSNI

Tags:

dom

gwt

jsni

I'm working in a native function inside a GWT application and I've tried this two methods: document.getElementById("id") returns null but $doc.getElementById() returns a valid element. Which is the difference (conceptually) between this methods? Thanks in advance.

like image 369
Jésica Avatar asked Sep 05 '11 13:09

Jésica


People also ask

What is Doc getElementById?

getElementById() The Document method getElementById() returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.

What can I use instead of document getElementById?

A commonly-used alternative to document. getElementById is using a jQuery selector which you read about more here.

What is the use of document getElementById .value in JavaScript?

Definition and Usage The getElementById() method returns an element with a specified value. The getElementById() method returns null if the element does not exist. The getElementById() method is one of the most common methods in the HTML DOM. It is used almost every time you want to read or edit an HTML element.

Can you use getElementById twice?

You can use the getElementById() method as many times as you wish, there's no quota assigned to that method. Save this answer. Show activity on this post. You can call getElementById multiple times and it will work.


1 Answers

The code of your GWT app runs in a (hidden) iframe, so document references that iframe's document (and window the iframe's browsing context). GWT thus initializes the variables $doc and $wnd to let you easily reference the document and browsing context (window) of the "host page" that loads the GWT app.

Note that linkers decide how the compiled code is loaded, the default one (std) and the newer xsiframe use iframes, whereas the deprecated xs loads your code in the same browsing context (so $doc == document and $wnd == window)

like image 152
Thomas Broyer Avatar answered Sep 25 '22 08:09

Thomas Broyer