Check if element is child of another in Dart

Issue

I need to check if a clicked element is child of another, using jQuery I would do: $(event.target).parents('#foo').length === 1 but with dart I have no clue.

void main(){
   (querySelector('body') as BodyElement).onClick.listen(onGlobalClick);
}

onGlobalClick(Event event){
 Element element = event.target;
 //Check if `element` is child of an element with an id of 'foo'
}

Solution

element.contains(event.target)

should return whether event.target is a descendant of element

Answered By – Günter Zöchbauer

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *