Reputation: 13602
I'm trying to trigger a click on html element (in dart).
In other words, how can I execute the function that is normally executed when the element is clicked ?
Here is an example:
import 'dart:html';
import 'dart:math';
main() {
querySelector("#first").onClick.listen((e) {
r() => new Random().nextInt(256);
querySelector("#first").style.color =
"rgb(${r()},${r()},${r()})";
});
querySelector("#second").onClick.listen((e) {
// pretend the first paragraph is clicked
});
}
see also: https://dartpad.dartlang.org/456f1ec945536caf310c
Upvotes: 1
Views: 996
Reputation: 657476
This should work to produce a mouse event
querySelector("#second").dispatchEvent(new MouseEvent(...))
Upvotes: 5