Skip to content

jQuery.fn.getBlock()

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

Overloads

jQuery.fn.getBlock(blockName)

Version added: 1.0.0

Summary

Returns a list of matched blocks, containing in the current set of jQuery objects.

Returns

A list of matched blocks if there are any; otherwise - an empty list.

Type: jQuery object

Parameters

blockName

The name of the block.

Type: String

Examples

Gets blocks by the name of the block:

HTML:

<html>
<body>
    <div id="product1" class="product"></div>
    <div class="products">
        <div id="product2" class="product"></div>
        <div id="product3" class="product"></div>
        <div class="offer"></div>
    </div>
    <div class="products">
        <div id="product4" class="product"></div>
    </div>
    <div id="product5" class="product"></div>
</body>
</html>

Code:

var $blocks = $('.products').getBlock('product');

Result:

The $blocks variable will contain three blocks with identifiers product2, product3 and product4.

jQuery.fn.getBlock(blockName, modifier)

Version added: 1.0.0

Summary

Returns a list of matched blocks, containing in the current set of jQuery objects.

Returns

A list of matched blocks if there are any; otherwise - an empty list.

Type: jQuery object

Parameters

blockName

The name of the block.

Type: String

modifier

One or more modifiers, separated by a space.

Type: String

Examples

Gets blocks by the name of the block and the modifier:

HTML:

<html>
<body>
    <div id="product1" class="product"></div>
    <div class="products">
        <div id="product2" class="product"></div>
        <div id="product3" class="product product_is-selected"></div>
        <div class="offer"></div>
    </div>
    <div class="products">
        <div id="product4" class="product product_is-selected"></div>
    </div>
    <div id="product5" class="product product_is-selected"></div>
</body>
</html>

Code:

var $blocks = $('.products').getBlock('product', 'is-selected');

Result:

The $blocks variable will contain two blocks with identifiers product3 and product4.

Gets blocks by the name of the block and a string of modifiers:

HTML:

<html>
<body>
    <div id="product1" class="product"></div>
    <div class="products">
        <div id="product2" class="product"></div>
        <div id="product3" class="product product_is-selected product_size_xs"></div>
        <div class="offer"></div>
    </div>
    <div class="products">
        <div id="product4" class="product product_is-selected"></div>
        <div id="product5" class="product product_is-selected product_size_xs product_is-focused"></div>
    </div>
    <div id="product6" class="product product_is-selected product_size_xs"></div>
</body>
</html>

Code:

var $blocks = $('.products').getBlock('product', 'is-selected size_xs');

Result:

The $blocks variable will contain two blocks with identifiers product3 and product5.

jQuery.fn.getBlock(blockName, modifierName, modifierValue)

Version added: 1.0.0

Summary

Returns a list of matched blocks, containing in the current set of jQuery objects.

Returns

A list of matched blocks if there are any; otherwise - an empty list.

Type: jQuery object

Parameters

blockName

The name of the block.

Type: String

modifierName

The name of the modifier.

Type: String

modifierValue

The value of the modifier.

Type: String

Examples

Gets blocks by the name of the block, the name of the modifier and the value of the modifier:

HTML:

<html>
<body>
    <div id="product1" class="product"></div>
    <div class="products">
        <div id="product2" class="product"></div>
        <div id="product3" class="product product_size_xs"></div>
        <div id="product4" class="product product_size"></div>
        <div class="offer"></div>
    </div>
    <div class="products">
        <div id="product5" class="product product_size_xs"></div>
    </div>
    <div id="product6" class="product product_size_xs"></div>
</body>
</html>

Code:

var $blocks = $('.products').getBlock('product', 'size', 'xs');

Result:

The $blocks variable will contain two blocks with identifiers product3 and product5

Clone this wiki locally