O
O
oe24y2020-01-19 10:10:34
Google Chrome
oe24y, 2020-01-19 10:10:34

How to emulate clicking on react elements from the console?

Tell me, how can I emulate a click on an element from the console?
On other sites, the usual click () on pure JS or Jquery works.
Here - no. I found a similar question
in history , but there is no answer to it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RaShe, 2020-01-23
@RaShe

What happens after the click? If the state changes, then you can do it with react dev tools and not trigger a click at all.

S
SerzN1, 2020-01-24
@SerzN1

var event = new MouseEvent('click', {
    'view': window,
    'bubbles': true,
    'cancelable': true
  });
var b = $0.dispatchEvent(event)

`$0` in this case is the currently selected element in chrome dev.tools and you can use `document.getElementById` and so on instead

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question