Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you reference the current selector as in jquery's $(this) within dart

Tags:

dart

Dart uses query('#selector')

if i wanted to get a reference to the result so i can do something with the selected item, what is the dart equivalent. I tried query(this) but

like image 960
BraveNewMath Avatar asked Jan 14 '23 17:01

BraveNewMath


2 Answers

If you need to use jQuery(this) or $(this) for the purpose of retrieving the target of an event:

$('.foo').click(function() {
  console.log($(this).hasClass('bar'));
});

In Dart you can write that like:

query('.foo').onClick.listen((MouseEvent e) {
  print(e.target.classes.contains('bar'));
});
like image 172
Kai Sellgren Avatar answered Feb 15 '23 23:02

Kai Sellgren


The Document.query(selector) function is not an equivalent of jQuery(selector) but an equivalent of Document.querySelector(selector). Thus you cannot get the selector used and you have to keep the reference aside.

If you want to use jQuery in Dart you can use it with the js package.

like image 36
Alexandre Ardhuin Avatar answered Feb 15 '23 23:02

Alexandre Ardhuin