# fromEvent

#### signature: `fromEvent(target: EventTargetLike, eventName: string, selector: function): Observable`

## Turn event into observable sequence.

### Examples

**Example 1: Observable from mouse clicks**

( [StackBlitz](https://stackblitz.com/edit/typescript-mfyefr?file=index.ts\&devtoolsheight=50) | [jsBin](http://jsbin.com/xikapewoqa/1/edit?js,console,output) | [jsFiddle](https://jsfiddle.net/btroncone/vbLz1pdx/) )

```js
// RxJS v6+
import { fromEvent } from 'rxjs';
import { map } from 'rxjs/operators';

//create observable that emits click events
const source = fromEvent(document, 'click');
//map to string with given event timestamp
const example = source.pipe(map(event => `Event time: ${event.timeStamp}`));
//output (example): 'Event time: 7276.390000000001'
const subscribe = example.subscribe(val => console.log(val));
```

### Related Recipes

* [Alphabet Invasion Game](https://www.learnrxjs.io/learn-rxjs/recipes/alphabet-invasion-game)
* [Battleship Game](https://www.learnrxjs.io/learn-rxjs/recipes/battleship-game)
* [Breakout Game](https://www.learnrxjs.io/learn-rxjs/recipes/breakout-game)
* [Car Racing Game](https://www.learnrxjs.io/learn-rxjs/recipes/car-racing-game)
* [Catch The Dot Game](https://www.learnrxjs.io/learn-rxjs/recipes/catch-the-dot-game)
* [Click Ninja Game](https://www.learnrxjs.io/learn-rxjs/recipes/click-ninja-game)
* [Flappy Bird Game](https://www.learnrxjs.io/learn-rxjs/recipes/flappy-bird-game)
* [Game Loop](https://www.learnrxjs.io/learn-rxjs/recipes/gameloop)
* [Horizontal Scroll Indicator](https://www.learnrxjs.io/learn-rxjs/recipes/horizontal-scroll-indicator)
* [HTTP Polling](https://www.learnrxjs.io/learn-rxjs/recipes/http-polling)
* [Lockscreen](https://www.learnrxjs.io/learn-rxjs/recipes/lockscreen)
* [Memory Game](https://www.learnrxjs.io/learn-rxjs/recipes/memory-game)
* [Mine Sweeper Game](https://www.learnrxjs.io/learn-rxjs/recipes/mine-sweeper-game)
* [Platform Jumper Game](https://www.learnrxjs.io/learn-rxjs/recipes/platform-jumper-game)
* [Progress Bar](https://www.learnrxjs.io/learn-rxjs/recipes/progressbar)
* [Save Indicator](https://www.learnrxjs.io/learn-rxjs/recipes/save-indicator)
* [Smart Counter](https://www.learnrxjs.io/learn-rxjs/recipes/smartcounter)
* [Space Invaders Game](https://www.learnrxjs.io/learn-rxjs/recipes/space-invaders-game)
* [Stop Watch](https://www.learnrxjs.io/learn-rxjs/recipes/stop-watch)
* [Swipe To Refresh](https://www.learnrxjs.io/learn-rxjs/recipes/swipe-to-refresh)
* [Tank Battle Game](https://www.learnrxjs.io/learn-rxjs/recipes/tank-battle-game)
* [Tetris Game](https://www.learnrxjs.io/learn-rxjs/recipes/tetris-game)
* [Type Ahead](https://www.learnrxjs.io/learn-rxjs/recipes/type-ahead)
* [Uncover Image Game](https://www.learnrxjs.io/learn-rxjs/recipes/uncover-image-game)

### Additional Resources

* [fromEvent](https://rxjs.dev/api/index/function/fromEvent) 📰 - Official docs

***

> 📁 Source Code: <https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/fromEvent.ts>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.learnrxjs.io/learn-rxjs/operators/creation/fromevent.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
