1

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.

1 Answer 1

8

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
});
Sign up to request clarification or add additional context in comments.

3 Comments

It should be noted that e can also be the direct implementation of any HTML element like InputElement, SpanElement, DivElement... I preferr this since it make it obvious what element I am dealing with
Do you mean to use e instead of this in this format e.style.background??
Yes. When you use JQuery each this points on the current element and $(this) gives a jQuery wrapper around this. In Dart, you don't have such wrapper but the API of Element is really straightforward and powerfull.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.