Skip to content
a jquery plugin to help defensive programming habits when using selectors.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

jQuery Expected

jQuery Expected is inspired by .NET's Enumerable.Single. It takes in an expected value and returns the collection if the number of items in the selector array matches the expected value. When the expected value doesn't match, an Error of type ExpectedValueError is thrown. ExpectedValueError is included in the global namespace.


try {
    $('selector').expected(1).html('hello world');
} catch (ex) {
    if (ex instanceof ExpectedValueError) {
        alert('Selector did not have expected length of 1');
    } else {
You can’t perform that action at this time.