How discover the element with the max font-size

时间:2015-05-24 21:36:21

标签: javascript html css fonts

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.

1 个答案:

答案 0 :(得分:0)

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;