getElementByValues<V> function

Element? getElementByValues<V>(
  1. String tag,
  2. ElementValueGetter getter,
  3. List<V> values, [
  4. ElementValueGetter? getter2,
  5. List<V>? values2,
])

selects in DOM an Element with tag and one of values provided by getter.

Implementation

Element? getElementByValues<V>(
    String tag, ElementValueGetter getter, List<V> values,
    [ElementValueGetter? getter2, List<V>? values2]) {
  if (tag.isEmpty) return null;
  if (values.isEmpty) return null;

  var allLinks = document.querySelectorAll(tag);
  if (allLinks.isEmpty) return null;

  if (getter2 != null) {
    if (values2 == null || values2.isEmpty) return null;

    var fond = allLinks.firstWhereOrNull((l) {
      var elemValue = getter(l);
      var ok = values.contains(elemValue);
      if (!ok) return false;
      var elemValue2 = getter2(l);
      var ok2 = values2.contains(elemValue2);
      return ok2;
    });
    return fond;
  } else {
    var fond = allLinks.firstWhereOrNull((l) {
      var elemValue = getter(l);
      return values.contains(elemValue);
    });

    return fond;
  }
}