• Checks if the Element(s), EventTarget(s), or CSS selector(s) specified as left and the Element, EventTarget, or CSS selector specified as right do not match.

    Parameters

    • left: OneOrManyOf<null | Target>

      One or many Element, EventTarget, or CSS selectors to check; if an array, returns true only if all elements don't match the target element input.

    • right: null | Target

      Element, EventTarget, or CSS selector to compare against.

    Returns boolean

    true if the elements do not match.

    This function doesn't throw if the specified left and/or right elements don't exist. Rather, it just returns false. This was a deliberate choice.

    HTML

    <ul>
    <li id="item-1">Item 1</li>
    <li id="item-2">Item 2</li>
    </ul>

    Code

    const item1 = findElement("#item-1")!;
    const item2 = findElement("#item-2")!;

    areElementsDifferent(item1, item2);
    // true

    areElementsDifferent(item1, "#item-1");
    // false

    areElementsDifferent(item1, null);
    // false