Skip to content

jQuery.fn.blockName()

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

Version added: 1.0.0

Summary

Returns the name of the first block of the current set of jQuery objects. The name of the block is taken from the first CSS class.

Returns

The name of the block if there are any blocks or elements in the current set of jQuery objects; otherwise - an empty string.

Type: String

Examples

Gets the name of the block:

HTML:

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

Code:

var blockName = $('.product').blockName();

Result:

'product'

Gets the name of the element's block:

HTML:

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

Code:

var blockName = $('.product__name').blockName();

Result:

'product'

Clone this wiki locally