Please, read the deprecation notice
jQuery.BEM is small jQuery plugin for comfortable working with HTML made by BEM methodology.
<div class="b-product">
<div class="b-product__name">Coffe</div>
<div class="b-product__price">$2</div>
</div>
<div class="b-product">
<div class="b-product__name">Tea</div>
<div class="b-product__price">$1</div>
</div>
$('.b-product:first').elem('name').block(); // $('.b-product:first > .b-product__name').closest('.b-product')
$('.b-product:first').elem('name').block(); // $('.b-product:first > .b-product__name').closest('.b-product')
<div class="b-product">...</div>
$('.b-product').mod('theme', 'premium'); // will get .b-product.b-product_theme_premium
$('.b-product').mod('premium', true); // will get .b-product.b-product_premium
<div class="b-product b-product_theme_premium">...</div>
$('.b-product').delMod('theme', 'premium'); // $('.b-product').removeClass('b-product_theme_premium');
$('.b-product').delMod('theme'); // remove the modifier "theme" of any value (.b-product_theme_*)
$('.b-product').mod('theme', false); // same
<div class="b-product b-product_theme_premium">...</div>
$('.b-product').mod('theme') // will return "premium"
$('.b-product').mod('discount'); // will rerurn null (non-existent modifier)
<div class="b-product b-product_theme_premium">...</div>
$('.b-product').hasMod('theme'); // true
$('.b-product').hasMod('theme', 'premium'); // true
$('.b-product').hasMod('theme', 'discount') // false
<div class="b-product">...</div>
$('.b-product').toggleMod('theme', 'premium', 'discount');
$('.b-product').hasMod('theme', 'premium'); // true
$('.b-product').hasMod('theme', 'discount') // false
$('.b-product').toggleMod('theme', 'premium', 'discount');
$('.b-product').hasMod('theme', 'premium'); // false
$('.b-product').hasMod('theme', 'discount') // true
<div class="b-product b-product_theme_premium">...</div>
<div class="b-product">...</div>
$('.b-product').byMod('theme', 'premium'); // instead of $('.b-product.b-product_theme_premium')
$('.b-product').byNotMod('theme', 'premium'); // instead of $('.b-product').not('.b-product_theme_premium')
$('.b-product').byMod('theme'); // filtering by modifier "theme" of any value (?)
You can subscribe to setmod
and delmod
events for obtain modifier data at the time thier setting or removal.
$('.block').on('setmod', function(e, modKey, modVal) {});
$('.block').on('delmod', function(e, modKey, modVal) {});
Use .ctx
function for change block context. For sample:
<div class="block">
<div class="block__elem some-block">
<div class="some-block__elem"></div>
</div>
</div>
$('.block').elem('elem').ctx('some-block').elem('elem');