# Checks

TIP

declare function hasAttr(name: string): boolean;
declare function hasProp(name: string): boolean;
declare function hasData(name: string): boolean;
declare function hasClass(classNames: string): boolean;
declare function matches(selector: string): boolean;

If you try to check on an empty collection and strict mode is on, then a NotEnoughElementsError will be thrown. Without strict mode, it will default to false.

# LightqueryCollection#hasAttr

Determine whether or not the first item has the given attribute:

µ([]).hasAttr("checked");
//-> throws NotEnoughElementsError (w/ strict mode)
//-> false (w/o strict mode)

µ(":checkbox").hasAttr("checked"); //-> true or false

TIP

hasAttr() is for the HTML attributes (thus visible on the DOM).

# LightqueryCollection#hasProp

Determine whether or not the first item has the given prop:

µ(/**/).hasProp("length"); //-> true or false

TIP

hasProp() is for JS properties of the DOM nodes/elements (usually not visible on the DOM).

# LightqueryCollection#hasData

Determine whether or not the first item has the data attribute:

µ(/**/).hasData("src"); //-> true or false

# LightqueryCollection#hasClass

Determine whether or not the first item has the given class:

µ(/**/).hasClass("my-class"); //-> true or false

TIP

Like many methods, hasClass accepts a spaced-separated string as its argument.

# LightqueryCollection#matches

Determine whether or not the first item matches the given CSS selector:

µ(/**/).matches(".my > .selector"); //-> true or false