HTMLGeolocationElement: HTMLGeolocationElement() constructor
HTML DOM
HTML DOM
The **`HTMLGeolocationElement()`** constructor creates a new HTMLGeolocationElement object instance.
## Syntax
```js-nolint
new HTMLGeolocationElement()
```
### Parameters
None.
### Return value
A new HTMLGeolocationElement object instance, if used internally by the browser.
Developers cannot use the `HTMLGeolocationElement()` constructor directly to create a new `HTMLGeolocationElement` instance: attempting to do so results in an "illegal constructor" error.
## Examples
### Creating a new `HTMLGeolocationElement` instance programmatically
To programmatically create a new `HTMLGeolocationElement` instance, instead of trying to use the constructor directly, you would create a new geolocation element instance using Document.createElement():
```js
const geo = document.createElement("geolocation");
```
You can then use it by appending it to the DOM:
```js
document.body.append(geo);
```
## Specifications
## Browser compatibility
## See also
- geolocation element
Cite this
"HTMLGeolocationElement: HTMLGeolocationElement() constructor". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/HTMLGeolocationElement/HTMLGeolocationElement JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy