Skip to content

jQuery.fn.hasModifier()

Evgenii Koriakin edited this page Oct 14, 2015 · 6 revisions

Overloads

jQuery.fn.hasModifier(modifier)

Version added: 1.0.0

Summary

Determines whether any of the set of jQuery objects has the modifier(s).

Returns

True if any of the set of jQuery objects has the modifier(s); otherwise - false.

Type: Boolean

Parameters

modifier

One or more modifiers, separated by a space.

Type: String

Examples

Determines whether any of the set of blocks has the modifier:

HTML:

<html>
<body>
    <div class="product"></div>
    <div class="product product_is-selected"></div>
    <div class="product"></div>
</body>
</html>

Code:

var hasModifier = $('.product').hasModifier('is-selected');

Result:

true

Determines whether any of the set of elements has the modifier:

HTML:

<html>
<body>
    <div class="product__name"></div>
    <div class="product__name product__name_is-selected"></div>
    <div class="product__name"></div>
</body>
</html>

Code:

var hasModifier = $('.product__name').hasModifier('is-selected');

Result:

true

Determines whether any of the set of blocks has all modifiers from a string of modifiers:

HTML:

<html>
<body>
    <div class="product"></div>
    <div class="product product_is-selected product_size_xs"></div>
    <div class="product"></div>
</body>
</html>

Code:

var hasModifier = $('.product').hasModifier('is-selected size_xs');

Result:

true

Determines whether any of the set of elements has all modifiers from a string of modifiers:

HTML:

<html>
<body>
    <div class="product__name"></div>
    <div class="product__name product__name_is-selected product__name_size_xs"></div>
    <div class="product__name"></div>
</body>
</html>

Code:

var hasModifier = $('.product__name').hasModifier('is-selected size_xs');

Result:

true

jQuery.fn.hasModifier(modifierName, modifierValue)

Version added: 1.0.0

Summary

Determines whether any of the set of jQuery objects has the modifier.

Returns

True if any of the set of jQuery objects has the modifier; otherwise - false.

Type: Boolean

Parameters

modifierName

The name of the modifier.

Type: String

modifierValue

The value of the modifier.

Type: String

Examples

Determines whether any of the set of blocks has the modifier with name and value:

HTML:

<html>
<body>
    <div class="product"></div>
    <div class="product product_size_xs"></div>
    <div class="product"></div>
</body>
</html>

Code:

var hasModifier = $('.product').hasModifier('size', 'xs');

Result:

true

Determines whether any of the set of elements has the modifier with name and value:

HTML:

<html>
<body>
    <div class="product__name"></div>
    <div class="product__name product__name_size_xs"></div>
    <div class="product__name"></div>
</body>
</html>

Code:

var hasModifier = $('.product__name').hasModifier('size', 'xs');

Result:

true

jQuery.fn.hasModifier(modifiers)

Version added: 1.0.0

Summary

Determines whether any of the set of jQuery objects has the modifier(s).

Returns

True if any of the set of jQuery objects has the modifier(s); otherwise - false.

Type: Boolean

Parameters

modifiers

A list of modifiers.

Type: Array

Examples

Determines whether any of the set of blocks has all modifiers from a list of modifiers:

HTML:

<html>
<body>
    <div class="product"></div>
    <div class="product product_is-selected product_size_xs"></div>
    <div class="product"></div>
</body>
</html>

Code:

var hasModifier = $('.product').hasModifier(
    [{ name: 'is-selected' }, { name: 'size', value: 'xs' }]
);

Result:

true

Determines whether any of the set of elements has all modifiers from a list of modifiers:

HTML:

<html>
<body>
    <div class="product__name"></div>
    <div class="product__name product__name_is-selected product__name_size_xs"></div>
    <div class="product__name"></div>
</body>
</html>

Code:

var hasModifier = $('.product__name').hasModifier(
    [{ name: 'is-selected' }, { name: 'size', value: 'xs' }]
);

Result:

true

Clone this wiki locally