简体   繁体   中英

How discover the element with the max font-size

I'm trying to answer the call of a function based on comparison of THIS element (keyword) font-size with font-sizes of other elements:

This is inside a prototype:

The self.settings.same is an array with the other elements.

self.settings.same.forEach(function (item) {
  var me    = parseInt(self.element.css('fontSize').substring(-1, 2), 10);
  var other = parseInt(item.css('fontSize').substring(-1, 2), 10);

  if (other > me) {
    return false;
  }

  return true;
});

I want return false if the others elements have the font-size bigger then the current element, but this is not working because it makes the loop only once, so the comparison occurs only once.

If you can return false only when all others elements are bigger than me , then this should work.

self.settings.same.forEach(function (item) {
  var me    = parseInt(self.element.css('fontSize').substring(-1, 2), 10);
  var other = parseInt(item.css('fontSize').substring(-1, 2), 10);

  if (other < me) {
    return true;
  }

});
return false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM