How to use each function, this from jquery to Dart Language?

Issue

I have a function in jquery as below

function findMax(){
 $( ".elements" ).each(function( ) {
  if($(this).css('z-index')>max1)
  max1=$(this).css('z-index');
  max1=parseInt(max1);
 });
}

I have to implement this function in Dart Language. Facing problems with syntaxes in using .each function and ‘this’ function.

Solution

The equivalent of jQuery :

$(".elements").each(function( ) {
  // do something with this being one of elements with a 'elements' class
  // you can access the current element with $(this)
});

is in Dart :

querySelectorAll('.elements').forEach((Element e) {
  // do something with e being one of elements with a 'elements' class
  // you can access the current element with e
});

Answered By – Alexandre Ardhuin

Answer Checked By – Dawn Plyler (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.